2014-04-04 32 views
0
$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 

当我输出这个,我得到一个表结构。我不想那样。 如何在每个新输出中只有名称和版本之间留有空格的新行?Powershell:平板电脑输出到一行空间的字符串

现在输出错误:

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

通缉输出:

Microsoft SQL Server System CLR Types 10.51.2500.0 

或者:

Microsoft SQL Server System CLR Types (10.51.2500.0) 
+0

你使用'格式Table'得到一个表格输出... – JNK

+0

可能是值得一读:http://myitforum.com/ cs2/blogs/gramsey/archive/2011/01/25/win32-product-is-evil.aspx –

回答

1

尝试与此更换整条生产线:

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

哦,你还有其他的格式表... Hangon – JNK

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

你可以这样说:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name, Version | % { write-host "$($_.name) ($($_.version))" }