Powershell 如何从1台设备中获取添加/删除程序列表,并使用将其与其他设备进行比较

Powershell 如何从1台设备中获取添加/删除程序列表,并使用将其与其他设备进行比较,powershell,addremoveprograms,Powershell,Addremoveprograms,我有两个远程设备,在这里我需要比较添加删除程序和使用powershell的设备。我该怎么做呢。有人能帮我吗 例如:- 需要比较A1计算机和B2计算机的appremove程序。Microsoft脚本编写人员检查注册表,而不是非常慢的Win32_产品类。下面是他们按名称搜索计算机列表的示例: $computers = Import-Csv “C:\PowerShell\computerlist.csv” $array = @() foreach($pc in $computers){ $c

我有两个远程设备,在这里我需要比较添加删除程序和使用powershell的设备。我该怎么做呢。有人能帮我吗

例如:-

需要比较A1计算机和B2计算机的appremove程序。

Microsoft脚本编写人员检查注册表,而不是非常慢的Win32_产品类。下面是他们按名称搜索计算机列表的示例:

$computers = Import-Csv “C:\PowerShell\computerlist.csv”
$array = @()

foreach($pc in $computers){
    $computername=$pc.computername

    #Define the variable to hold the location of Currently Installed Programs
    $UninstallKey=”SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall” 

    #Create an instance of the Registry Object and open the HKLM base key
    $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey(‘LocalMachine’,$computername) 

    #Drill down into the Uninstall key using the OpenSubKey Method
    $regkey=$reg.OpenSubKey($UninstallKey) 

    #Retrieve an array of string that contain all the subkey names
    $subkeys=$regkey.GetSubKeyNames() 

    #Open each Subkey and use GetValue Method to return the required values for each
    foreach($key in $subkeys){
        $thisKey=$UninstallKey+”\\”+$key 
        $thisSubKey=$reg.OpenSubKey($thisKey) 
        $obj = New-Object PSObject
        $obj | Add-Member -MemberType NoteProperty -Name “ComputerName” -Value $computername
        $obj | Add-Member -MemberType NoteProperty -Name “DisplayName” -Value $($thisSubKey.GetValue(“DisplayName”))
        $obj | Add-Member -MemberType NoteProperty -Name “DisplayVersion” -Value $($thisSubKey.GetValue(“DisplayVersion”))
        $obj | Add-Member -MemberType NoteProperty -Name “InstallLocation” -Value $($thisSubKey.GetValue(“InstallLocation”))
        $obj | Add-Member -MemberType NoteProperty -Name “Publisher” -Value $($thisSubKey.GetValue(“Publisher”))
        $array += $obj
    } 
}
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion
我们可以将对象列表与compare Object进行比较,以查看B PC中缺少哪些软件:

$ComputerA = $array | Where-Object { $_.ComputerName -like 'ComputerA' } 
$ComputerB = $array | Where-Object { $_.ComputerName -like 'ComputerB' } 

Compare-Object $ComputerA $ComputerB -Property DisplayName,DisplayVersion

DisplayName            DisplayVersion SideIndicator
-----------            -------------- -------------
Notepad++ (64-bit x64) 7.8.9          <=           

当然,这很简单…你能告诉我们你的代码在哪里有问题吗?$Computer=get content C:\computername.txt get WmiObject Win32_Product-computername$Computer |选择PSComputerName,Name,Version |导出csv C:\tools\Current-Installed-Applications.csv当前我正在使用上述代码,其中,这将仅用于从多个远程设备获取addremove数据。但是我正在检查从多个设备中提取的数据,然后进行比较。那么你想将软件与每台计算机进行比较吗?如果你只比较2,这是有意义的,但是如果你比较多,就你要找的东西而言,这是没有意义的。您可以在$Computers{}中使用Foreach$Computer遍历返回每个计算机数据的计算机。您是否有一台主计算机要与之比较?在我的场景中,一台计算机是主计算机到A1计算机,B台计算机是主计算机到B1计算机,同样,我有50台主计算机和50台其他计算机。每台计算机是主计算机到另一台计算机