Powershell-更改输出格式 [英] Powershell - Change format of output
本文介绍了Powershell-更改输出格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改代码产生的输出的外观:
How can I change the presenation of the output my code produces:
$apps = Import-CSV apps.csv
$computers = Import-CSV compobj.csv
foreach($computer in $computers) {
$computerLob = $computer.lob
$lobApps = $apps | ? {$_.lob -eq $computerLob }
foreach($app in $lobApps){
$computerHostname = $computer.hostname
$appLocation = $app.location
$installed=Test-Path "\\$computerHostname\$appLocation"
New-Object PSObject @{Computer=$computer.hostname;App=$app.appname;Installed=$installed}
}
}
我希望更改代码的显示形式.看起来是这样的:
I would like for the presentation of the code to be changed. This is how it looks like:
Name Value
---- -----
Installed True
App App1
Computer 171.159.192.10
Installed True
App App2
Computer 171.159.192.10
我希望它看起来像这样:
I'd like for it to look like this:
Computer App1 App2
----------- ------ -----
171.159.192.10 True True
推荐答案
您正在将哈希表作为其ctor参数而不是属性集传递给New-Object
.更改为:
You're passing the hashtable to New-Object
as its ctor argument instead of a property set. Change it to:
New-Object PSObject -Property @{
Computer=$computer.hostname
App=$app.appname
Installed=$installed
}
这篇关于Powershell-更改输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文