Подскажите, как можно получить дату последнего обновления списка серверов?
Есть такой вариант:
Код:
Код: Выделить всё
cls
$ScriptBlock = {
$hash=@{}
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$hash[$env:Computername] = $Searcher.QueryHistory(1,1) | select -ExpandProperty Date
$hash
}
$server_list = cat d:\server_list.txt
foreach ($server in $server_list) {
Invoke-Command -ComputerName $server -ScriptBlock $ScriptBlock
}Но этот вариант не на всех серверах работает. На некоторых возвращается ошибка, о недоступности RPC...
Цитата:
[host-1234] Connecting to remote server host-1234 failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default,
the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (host-1234:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
Альтернативный вариант, получать по wmi, но с ним тоже проблемы, он возвращается неправильные даты.
Код:
Код: Выделить всё
$server = "host-1234"
Get-HotFix -computername $server | where {$_.InstalledOn} | sort InstalledOn -desc | select InstalledOn -First 1Вероятно это связано с региональными настройками. Например, последнее обновление было 18.12.2015, а выводит 12.10.2015. Даже если прикинуть, что он выводит в формате MM/dd/YYYY. Дата всё равно не верная...