【发布时间】:2014-03-06 18:56:56
【问题描述】:
我正在尝试远程获取我们服务器上的所有补丁,以便我们知道什么有什么。下面是我为实现这一目标而编写的脚本。但是,当我执行脚本时,我只会获得运行脚本的本地机器的补丁。我做错了什么?
$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;
}
}
【问题讨论】:
-
您是否在这些计算机上检查过 c:\new?我怀疑您的 PSSession 中的 CSV 位于远程计算机上,而不是您自己的计算机上。
-
是的,它不会将它发布到它正在寻找的计算机上,而是将它放在运行脚本的本地计算机上。但是,我确实在获得所有人许可的情况下创建了一条 UNC 路径,结果如下:
Access to the path '\\server name\d$\Patches\sample.csv' is denied. + CategoryInfo : OpenError: (:) [Export-Csv], UnauthorizedAccessException + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand -
您是否尝试过仅使用 WMI? Get-WMIObject Win32_QuickFixEngineering -ComputerName $name.
-
@EBGreen - 不,我没有。虽然,我尽量远离我们的 WMI 查询,因为当我们查询 WMI 时某些系统会崩溃。我正在尝试了解网络及其所有 Windows 计算机。想一想,我喜欢它!
-
明确一点,Get-Hotfix 无论如何都使用 WMI。
标签: powershell