簡體   English   中英

為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM