Question

$allSoftwareObj = Get-WmiObject -Class Win32_Product | Select-Object -Property Name, Version | ft -HideTableHeaders | ft -Wrap -AutoSize -Property Name, Version

$allSoftware = Out-String -InputObject $allSoftwareObj 
echo $allSoftware

When I output this, I get a table structure. I don't want that. How to get a new line per new output with only space between the Name and Version?

Wrong output now:

Microsoft SQL Server System CLR Types                           10.51.2500.0                                                                                  
SQL Server 2012 Client Tools                                    11.1.3000.0 

Wanted output:

Microsoft SQL Server System CLR Types 10.51.2500.0

Or:

Microsoft SQL Server System CLR Types (10.51.2500.0)
Was it helpful?

Solution

Try replacing the whole line with this:

Get-WmiObject -Class Win32_Product |  % {"$($_.Name) ($($_.Version))"}

OTHER TIPS

$allSoftwareObj = Get-WmiObject -Class Win32_Product | %{ $_.Name + " " + $_.Version}
$allSoftwareObj

You can do it like this:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name, Version | % { write-host "$($_.name) ($($_.version))" }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top