gpt4 book ai didi

powershell - Powershell-更改输出格式

转载 作者:行者123 更新时间:2023-12-03 01:19:18 26 4
gpt4 key购买 nike

如何更改代码产生的输出的外观:

$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}
}
}

我希望更改代码的显示方式。它是这样的:
Name                         Value                                                                                                            
---- -----
Installed True
App App1
Computer 171.159.192.10
Installed True
App App2
Computer 171.159.192.10

我希望它看起来像这样:
Computer                 App1    App2
----------- ------ -----
171.159.192.10 True True

最佳答案

您将哈希表作为其ctor参数而不是属性集传递给New-Object。更改为:

New-Object PSObject -Property @{
Computer=$computer.hostname
App=$app.appname
Installed=$installed
}

关于powershell - Powershell-更改输出格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19624304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com