首页 > 解决方案 > 获取安装在远程服务器上的特定 KB

问题描述

在此处输入图像描述尝试运行以下 powershell 脚本以从列表中查找 kbs,安装在远程服务器上,以及从列表中。

$computers = gc C:\users\xxx\Desktop\powershell\computers.txt
$patches = gc C:\users\xxx\Desktop\powershell\patch.txt
$credentials = Get-Credential
 

 foreach ($patch in $patches){
 
 Get-HotFix -id $patch -ComputerName $computers -OutVariable results -ErrorAction SilentlyContinue -Credential $credentials
 
 if ($results -ne $null) {
 
 $results | Out-File C:\users\xxx\Desktop\powershell\result.txt -Append -Force
 
 }
 
 else {
 
 Add-content "$computer missing $Patch" -path "mypath\missing.txt"
 
 }
 
 }

并收到以下错误:

Get-HotFix : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the 
command again.
At line:8 char:38
+  Get-HotFix -id $patch -ComputerName $computers -OutVariable results  ...
+                                      ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-HotFix], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetHotFixCommand

标签: powershell

解决方案


这是做什么的?

$computers = gc C:\users\xxx\Desktop\powershell\computers.txt
$patches = gc C:\users\xxx\Desktop\powershell\patch.txt
$credentials = Get-Credential
 
Foreach($Computer in $computers){
        foreach ($patch in $patches){
 
 Get-HotFix -id $patch -ComputerName $Computer -OutVariable results -ErrorAction SilentlyContinue -Credential $credentials
 
 if ($results -ne $null) {
 
 $results | Out-File C:\users\xxx\Desktop\powershell\result.txt -Append -Force
 
 }
 
 else {
 
 Add-content "$computer missing $Patch" -path "mypath\missing.txt"
        }
    }
 
 }


推荐阅读