我如何重组这个powershell命令的输出?
Get-WmiObject -Class Win32_Service -Property Name,StartMode,State -Filter "Name='Fax'"|findstr /r /c:'^[A-Z]'
输出:
Name : Fax
StartMode : Manual
State : Stopped
OUTPUT Desired:
Fax;Manual;Stopped
我必须使用,设置命令?或者我可以在命令行上做其他事情?
提前致谢
答案 0 :(得分:0)
如果我们只是用分号分隔的字符串...你可以从Get-WmiObject
输出的对象的属性创建一个字符串,以获得所需的输出。
示例:
PS C:\> $object = Get-WmiObject -Class Win32_Service -Property Name,StartMode,State -Filter "Name='Fax'"
# Example 1: Concatenating strings
PS C:\> $object.Name+";"+$object.StartMode+";"+$object.State
Fax;Manual;Stopped
# Example 2: Using string joining
PS C:\> [string]::join(';',$object.Name,$object.StartMode,$object.State)
Fax;Manual;Stopped
# Example 3: Using string joining with an array
PS C:\> $array = @($object | % { $_.Name, $_.StartMode, $_.State })
PS C:\> [string]::join(';',$array)
Fax;Manual;Stopped
# Example 4: The join operator
PS C:\> $object.Name,$object.StartMode,$object.State -join ";"
Fax;Manual;Stopped