[英]i trying to collect different info with Get-ADComputer, Get-WmiObject and Get-windowsfeature
[英]Calling Get-WMIObject on multiple computers selected via Get-ADComputer
我試圖在通過Get-ADComputer選擇的多台計算機上調用Get-WMIObject(gwmi)作為后台作業。
我的第一次嘗試是
$job = Get-ADComputer -filter "name -like '*t90*'" | % { gwmi -computername $_.name -query "select name,username from win32_computersystem" -asjob -throttlelimit 10 }
但是,由於我為返回的每個計算機對象調用一次gwmi,因此創建了數百個后台作業,而且我不認為它們會共同遵守ThrottleLimit。
我這樣做對嗎?
我知道gwmi也可以接受computername屬性的數組,如下所示:
$job = gwmi -computername "computer1","computer2","computer3" -query "select * from win32_computersystem" -asjob -throttlelimit 10
由於gwmi僅被調用一次,因此以這種方式完成的工作只能完成一項工作,而不是數百項工作。 那是我應該做的方式嗎? 而且,如果是這樣, 我如何將Get-ADComputer的輸出作為數組提供給gwmi?
謝謝!
首先獲取所有計算機名稱,並將它們傳遞給computerName參數:
$cn = Get-ADComputer -filter "name -like '*t90*'" | select -expand name
$job = gwmi -computername $cn -query "select name,username from win32_computersystem" -asjob -throttlelimit 10
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.