我列出了几个OU中的广告计算机,然后在每个OU上运行Invoke-Command
,但不知何故,它不会将结果从Get-ADComputer
传递到Invoke-Command
。我究竟做错了什么?它只会产生第一个OU中找到的第一台PC。
$DesktopOUs = 'OU=aaa,DC=aaa,DC=com',
'OU=bbb,DC=aaa,DC=com'
$PCName = $DesktopOUs | foreach {
Get-ADComputer -Filter * -Properties * -SearchBase $_ |
Select-Object -ExpandProperty Name
}
Invoke-Command -ComputerName $pcname -ScriptBlock {
$win7kb = "*KB4025341*"
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) |
Where-Object {$_.title -like $win7kb} |
Select-Object Date,
@{name="Operation"; expression={switch($_.operation){1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}},
@{name="Status"; expression={switch($_.resultcode){1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"}; 4 {"Failed"}; 5 {"Aborted"}}}},
Title
} | Out-GridView -Title "Win7"
答案 0 :(得分:1)
稍微更改一下(排除过滤器,只运行3台计算机) 我在我的机器上运行它,没有任何问题......
$PCName = Get-ADComputer -Filter * -Properties * |
Select-Object -ExpandProperty Name
$PCName[4..6] | % { Invoke-Command -ComputerName $_ -ScriptBlock {1} }