You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Out-GridView列添加自定义对象?附远程获取安装程序代码

Adding Custom Columns to Out-GridView for Installed Apps

Nice work on the initial script to pull installed apps from both 32-bit and 64-bit registry paths! Adding custom columns to your Out-GridView output is straightforward using calculated properties with Select-Object—this lets you inject new, meaningful columns alongside the existing app data.

Step 1: Add an Architecture Column (Distinguish 32/64-bit Apps)

Since you’re querying two separate registry paths, adding an Architecture column will help you quickly identify which apps are 32-bit vs 64-bit. Here’s the modified code:

$installed_apps = Invoke-Command -computername P1184CDC -scriptblock {
    # Fetch 64-bit apps and add Architecture column
    Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
        Where-Object DisplayName -ne $null |
        Select-Object *, @{Name='Architecture'; Expression={'64-bit'}}

    # Fetch 32-bit apps and add Architecture column
    Get-ItemProperty "HKLM:\Software\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
        Where-Object DisplayName -ne $null |
        Select-Object *, @{Name='Architecture'; Expression={'32-bit'}}
}

$installed_apps | Out-GridView -Wait

The @{Name='Architecture'; Expression={'64-bit'}} syntax creates a calculated column:

  • Name sets the column header in Out-GridView
  • Expression defines the value for each row (here, hardcoding "64-bit" or "32-bit" based on the registry path)

Step 2: Add Additional Custom Columns (e.g., Formatted Install Date)

If you want to clean up raw data like the default InstallDate (a string like 20231005), you can add a formatted date column. Here’s how:

$installed_apps = Invoke-Command -computername P1184CDC -scriptblock {
    # 64-bit apps with Architecture and Formatted Install Date
    Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
        Where-Object DisplayName -ne $null |
        Select-Object *, 
            @{Name='Architecture'; Expression={'64-bit'}},
            @{Name='InstallDateFormatted'; Expression={
                if ($_.InstallDate) {
                    [DateTime]::ParseExact($_.InstallDate, 'yyyyMMdd', $null).ToString('MM/dd/yyyy')
                } else {
                    'N/A'
                }
            }}

    # 32-bit apps with Architecture and Formatted Install Date
    Get-ItemProperty "HKLM:\Software\wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
        Where-Object DisplayName -ne $null |
        Select-Object *, 
            @{Name='Architecture'; Expression={'32-bit'}},
            @{Name='InstallDateFormatted'; Expression={
                if ($_.InstallDate) {
                    [DateTime]::ParseExact($_.InstallDate, 'yyyyMMdd', $null).ToString('MM/dd/yyyy')
                } else {
                    'N/A'
                }
            }}
}

$installed_apps | Out-GridView -Wait

Step 3: Limit Columns for Clarity

If you don’t need all the default properties returned by Get-ItemProperty, replace * with a list of specific properties to keep your Out-GridView focused:

Select-Object DisplayName, DisplayVersion, Publisher,
    @{Name='Architecture'; Expression={'64-bit'}},
    @{Name='InstallDateFormatted'; Expression={...}}

Feel free to adjust the calculated properties to match any custom columns you need—whether it’s a status flag, a parsed version number, or something else!

内容的提问来源于stack exchange,提问作者Rakha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:45:07