简体   繁体   English

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

[英]Adding a custom object for Out-GridView column

Let's say I have : 比方说我有:

$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

This returns all the installed apps (32bit for the first command and 64bit for the command containing wow6432node) in a nice gridview: 这将在一个漂亮的gridview中返回所有已安装的应用程序(第一个命令为32位,包含wow6432node的命令为64位):

在此输入图像描述

I'm trying to add an "Architecture" column to the results, so i can identify all 64 bit objects returned from the command: 我正在尝试在结果中添加“架构”列,因此我可以识别从命令返回的所有64位对象:

 Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"| ? DisplayName -ne 

and all 32 bit objects returned from the command : 以及从命令返回的所有32位对象:

Get-ItemProperty "HKLM:\Software\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*" | ? DisplayName -ne $null

Right now they are all together but it would be nice to be able to sort them by 32bit or 64bit type. 现在他们都在一起但是能够按32位或64位类型对它们进行排序会很好。

I think I have to use New-Object PsObject like for example: 我想我必须使用New-Object PsObject,例如:

$architecture = New-Object PSObject -Property @{ 
Architecture = "x86"
}

in a ForEach loop but i'm far from comfortable with how to set it all together with the apps returned from the command. 在一个ForEach循环中,但我对如何将它们与命令返回的应用程序一起设置完全不太熟悉。 Thank you for your time! 感谢您的时间!

This will add an 'Architecture' property to the returned objects (and, hence, a corresponding column in the GridView): 这将为返回的对象添加“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

Incidentally, the wow6432node node is where 32-bit apps read/write, not 64-bit. 顺便说一句, wow6432node节点是32位应用程序读/写的地方,而不是64位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM