powershell - 为Out-GridView列添加自定义对象

标签 powershell object gridview

假设我有:

$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位):

enter image description here

我正在尝试向结果添加“体系结构”列,以便我可以识别从命令返回的所有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/

相关文章:

c++ - C++ 中的对象究竟是什么?

java.lang.NullPointerException : Loading three charts (from github) into a 2x2 GridView

azure - 如何将 azure cli list 命令的值获取到变量中?

powershell - PowerShell 中 Power BI Rest API 的错误处理

powershell - 如何在 PowerShell 中使用公共(public) IP 地址将 EC2 实例启动到 VPC?

powershell - 如何在PowerShell 1.0中使用STA模式?

javascript - 如何在 Javascript 中检查每个对象字段的深度

class - class() : and class(object): in python 2. 6-3.x 之间有区别吗?

c# - MultiView 和 GridView 分页问题

c# - 必须在使用 DataView 之前设置 DataTable