且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除Powershell输出中的空白行

更新时间:2023-12-03 19:16:22

尝试以下方法:

($OSInfo `
    | Format-List `
        @{Name="OS Name";Expression={$_.Caption}}, 
        @{Name="OS Boot Time";Expression={$_.ConvertToDateTime($_.LastBootUpTime)}}, 
        @{Name="OS Install Date";Expression={$_.ConvertToDateTime($_.InstallDate)}}  `
    | Out-String).Trim()

这将清除Format-List产生的所有多余的空白行.您可能需要插入一些自己要控制的东西.

That'll clean up all the extraneous blank lines produced by Format-List. You may need to insert a couple of your own that you get to control.