powershell - 获取安装在远程服务器上的特定 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
解决方案
这是做什么的?
$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"
}
}
}
推荐阅读
- node.js - 执行 npm 安装代码 ENOENT 系统调用重命名时出错
- c# - 如何从后置摄像头更改为前置摄像头?
- signals - 信号 Godot 内的意外分配
- mysql - 如何在 rails5 上取出每个具有 parent_ids 限制的孩子
- php - 设置与 GET 参数相同的 $_SESSION 值是否存在安全风险 - PHP?
- visual-studio-code - 我用 xkb 将 RALT 反弹到退格,但它在 VS Code 中不起作用
- performance - 选择列时访问子表单对象挂起?
- java - 使用 Lombok @Slf4j 时如何使来自其他依赖项的日志静音
- python - 如何更改我的代码中的 for 循环以在我的数据框中为我提供一个额外的列?
- python-3.x - 有什么区别?