我有以下内容,我想将所有输出加入一行 - 所以输出看起来像:
TCPIP.sys版本是$ 1“。”两美元“。” 3美元“。” $四个
我尝试在powershell中加入他们,但我收到以下错误:
PS C:\ Windows> $ one =(get-childitem c:\ windows \ system32 \ drivers \ tcpip.sys).Versioninfo.ProductMajorPart | fl *
PS C:\ Windows> $ 2 =(get-childitem c:\ windows \ system32 \ drivers \ tcpip.sys).Versioninfo.ProductMinorPart | fl *
PS C:\ Windows> $ 3 =(get-childitem c:\ windows \ system32 \ drivers \ tcpip.sys).Versioninfo.ProductBuildPart | fl *
PS C:\ Windows> $ 4 =(get-childitem C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ TCPIP.SYS).Versioninfo.ProductPrivatePart | fl *
错误:
PS C:\ Windows> write-host = $ one $ two = Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntr yData
答案 0 :(得分:1)
像这样:
$one = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMajorPart).tostring()
$two = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMinorPart).tostring()
$three = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductBuildPart).tostring()
$four = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductPrivatePart).tostring()
write-host "TCPIP.sys version is $one.$two.$three.$four"
但这在一行中也是如此:
$a = (get-childitem c:\windows\system32\drivers\tcpip.sys).VersionInfo.ProductVersion
write-host "TCPIP.sys version is $a"
答案 1 :(得分:0)
无需查询tcpip.sys四次。您可以从ProductVersion属性获取信息:
(get-childitem $env:windir\system32\drivers\tcpip.sys).Versioninfo.ProductVersion
您也可以使用Join运算符:
$one,$two,$three,$four -join '.'