Question

How can i reorganizate the otuput, of this powershell command?

Get-WmiObject -Class Win32_Service -Property Name,StartMode,State -Filter "Name='Fax'"|findstr /r /c:'^[A-Z]'

OUTPUT:

Name             : Fax
StartMode        : Manual
State            : Stopped

OUTPUT Desired:

Fax;Manual;Stopped

I have to use, set comand? or i can do something else, on command line?

Thanks in advance

Was it helpful?

Solution

If we're just doing a semi-colon delimited string... you can create a string from the properties of the object output by Get-WmiObject to get your desired output.

Example:

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

You can read more about the -join operator here, and more about [string]::join here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top