我需要使用 PowerShell 比较开发环境和生产环境中已安装的补丁。我该怎么做?
答案1
我最近在博客中讨论了这个问题,并想出了这个脚本。您可以以两台机器上的管理员用户身份运行它,也可以使用命令-Credential
上的选项get-hotfix
。
$server1 = Read-Host "Server 1"
$server2 = Read-Host "Server 2"
$server1Patches = get-hotfix -computer $server1 | Where-Object {$_.HotFixID -ne "File 1"}
$server2Patches = get-hotfix -computer $server2 | Where-Object {$_.HotFixID -ne "File 1"}
Compare-Object ($server1Patches) ($server2Patches) -Property HotFixID
答案2
clear-host
$machine1=Read-Host "Enter Machine Name 1:-"
$machine2=Read-Host "Enter Machine Name 2:-"
$machinesone=@(Get-wmiobject -computername $machine1 -Credential Domain\Adminaccount -query 'select hotfixid from Win32_quickfixengineering')
$machinestwo=@(Get-WmiObject -computername $machine2 -Credential Domain\Adminaccount -query 'select hotfixid from Win32_quickfixengineering')
Compare-Object -RefernceObject $machinesone -DiffernceObject $machinestwo -Property hotfixid