![](/img/trans.png)
[英]PowerShell - custom object - order of appearance in Out-GridView
[英]Adding a custom object for Out-GridView column
比方说我有:
$installed_apps = invoke-command -computername P1184CDC -scriptblock {
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"| ? DisplayName -ne $null
Get-ItemProperty "HKLM:\Software\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*" | ? DisplayName -ne $null
}
$installed_apps | Out-GridView -wait
这将在一个漂亮的gridview中返回所有已安装的应用程序(第一个命令为32位,包含wow6432node的命令为64位):
我正在尝试在结果中添加“架构”列,因此我可以识别从命令返回的所有64位对象:
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"| ? DisplayName -ne
以及从命令返回的所有32位对象:
Get-ItemProperty "HKLM:\Software\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*" | ? DisplayName -ne $null
现在他们都在一起但是能够按32位或64位类型对它们进行排序会很好。
我想我必须使用New-Object PsObject,例如:
$architecture = New-Object PSObject -Property @{
Architecture = "x86"
}
在一个ForEach循环中,但我对如何将它们与命令返回的应用程序一起设置完全不太熟悉。 感谢您的时间!
这将为返回的对象添加“Architecture”属性(因此,GridView中的相应列):
$installed_apps = invoke-command -scriptblock {
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object DisplayName -ne $null |
Add-Member -MemberType NoteProperty -Name Architecture -Value "64-bit" -PassThru
Get-ItemProperty "HKLM:\Software\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object DisplayName -ne $null |
Add-Member -MemberType NoteProperty -Name Architecture -Value "32-bit" -PassThru
}
$installed_apps | Out-GridView -wait
顺便说一句, wow6432node节点是32位应用程序读/写的地方,而不是64位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.