假设我有:
$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位)读取/写入的节点。
关于powershell - 为Out-GridView列添加自定义对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49650698/