在客户端计算机上查找图表

时间:2020-06-24 11:13:41

标签: powershell

我有一个客户想要找到公司所有已安装的程序,我写了一个脚本,但是我不想让脚本每次都为每个计算机显示相同的程序,我想查看整个安装

  $computers = get-adcomputers -filter *
  foreach($computer in $computers){
  Get-ItemProperty 
  HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | 
  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format- 
  Table –AutoSize}

1 个答案:

答案 0 :(得分:0)

我没有对此进行测试,但是您可以尝试

$computers = (Get-ADComputer -Filter *).DNSHostName   # or use .Name or .CN

$software = Invoke-Command -ComputerName $computers {
                Get-ItemProperty -Path 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
            }
$software | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate -Unique |
            Format-Table -AutoSize

P.S.1您需要在所有计算机上具有管理员权限才能执行此操作

P.S.2别忘了还有HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall


显然,您遇到了计算机脱机的问题。
为了解决这个问题,您需要添加一个循环,以便可以测试计算机是否可以访问。

$computers = (Get-ADComputer -Filter *).Name   # or use .CN

# loop through the collection and (if reachable) get the software list
$result = foreach ($computer in $computers) {
    # test if the computer is online
    if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
        # output the properties you need to get collected in variable $result
        Invoke-Command -ComputerName $computer {
            Get-ItemProperty -Path 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
        } | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
    }
    else {
        Write-Warning "Computer $computer is off-line"
    }
}

$software = $result | Select-Object * -Unique

# output to console
$software | Format-Table -AutoSize

# output to CSV file
$software | Export-Csv -Path 'D:\Software.csv' -NoTypeInformation