[英]How to find PST files on remote computers using Powershell script
[英]Powershell script is slow to find computers
我有一個腳本應該在 AD 中搜索具有相同名稱的不同 OU 中的計算機。 例如。
Get-ADComputer -filter * -Searchbase "OU=domain,DC=home,DC=com" -properties * |
Where-Object {$_.DistinguishedName -like "*XXX09*"} |
Select name, DistinguishedName
一切正常,但速度非常慢,有沒有辦法加快速度,或者以不同的方式構建腳本?
您不僅可以通過使用過濾器來加快速度,而且使用-Properties *
會要求所有屬性。 在這種情況下,這是無用且耗時的,因為您只想檢索 Name 和 DistinguishedName。
默認情況下, Get-ADCumputer
已經返回以下屬性:
DistinguishedName, DNSHostName, Enabled, Name, ObjectClass, ObjectGUID, SamAccountName, SID, UserPrincipalName
。
嘗試
Get-ADComputer -Filter "DistinguishedName -like '*XXX09*'" | Select-Object Name, DistinguishedName
在搜索期間而不是之后使用過濾器將大大減少查詢時間。
Get-ADComputer -filter 'DistinguishedName -like "*XXX09*"' -Searchbase "OU=domain,DC=home,DC=com" -properties * | select name, DistinguishedName
您可能需要稍微調整查詢,但我用 'name' 而不是 'DistinguishedName' 對其進行了測試,效果很好(而且速度更快;))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.