我试图远程获取我们服务器上的所有补丁,这样我们就知道什么是什么了。下面是我为实现这一目标而编写的脚本。但是,当我执行脚本时,我只得到运行脚本的本地机器的补丁。我做错了什么?
$computers = Get-ADComputer -Filter * -Properties operatingsystem;
$filter = "Windows Server*"
foreach($computer in $computers)
{
if($computer.OperatingSystem -like $filter)
{
$name = $computer.Name.ToString();
write-host "Working on computer: "$name
New-PSSession -ComputerName $name;
Enter-PSSession -ComputerName $name | Get-HotFix | Export-Csv "c:\new\$name patches.csv";
Exit-PSSession;
}
}发布于 2014-03-06 19:25:19
Enter-PSSession只具有交互性。对于脚本编写,您需要使用Invoke-Command
$computers = Get-ADComputer -Filter * -Properties operatingsystem;
$filter = "Windows Server*"
foreach($computer in $computers)
{
if($computer.OperatingSystem -like $filter)
{
$name = $computer.Name.ToString();
write-host "Working on computer: "$name
Invoke-Command -ScriptBlock {Get-HotFix} -ComputerName $name |
Export-Csv "c:\new\$name patches.csv"
}
}https://stackoverflow.com/questions/22233470
复制相似问题