Powershell-抓取已安装软件

这是一个PowerShell脚本,用于读取Windows注册表中的卸载键,从而列出已安装在系统上的软件。它遍历了本地机器和当前用户的卸载路径,并考虑到了在64位操作系统上安装的32位软件。脚本会过滤掉重复的软件名称,并输出包含软件名称、发布者和版本信息的产品实体。
摘要由CSDN通过智能技术生成
function Get-InstalledSoftwares
{
    #
    # Read registry key as product entity.
    #
    $script:lastname=@();
    function ConvertTo-ProductEntity
    {
        param([Microsoft.Win32.RegistryKey]$RegKey)
        $product = '' | select Name,Publisher,Version
        $product.Name =  $_.GetValue("DisplayName")
        $product.Publisher = $_.GetValue("Publisher")
        $product.Version =  $_.GetValue("DisplayVersion")

        if($product.Name  -in $script:lastname){            
        }
        else{
            if(-not [string]::IsNullOrEmpty($product.Name) -and -not [string]::IsNullOrEmpty($product.Publisher)){
                $product
                $script:lastname=$script:lastname+$_.GetValue("DisplayName")
            }
            
        }
        

        
    }

    $UninstallPaths = @(,
    # For local machine.
    'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
    # For current user.
    'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall')

    # For 32bit softwares that were installed on 64bit operating system.
    if([Environment]::Is64BitOperatingSystem) {
        $UninstallPaths += 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
    }


    $UninstallPaths | foreach {
        Get-ChildItem $_ |foreach {
            ConvertTo-ProductEntity -RegKey $_
        }
    }
}


Get-InstalledSoftwares
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值