![](/img/trans.png)
[英]How can I use PowerShell to copy the same file to many directories with the same name?
[英]powershell query - how many OR can i use?
我在 powershell 中找不到有關 -Filter 限制的任何信息我想使用以下命令查詢 Exchange 服務器上的許多組
Get-DistributionGroup
但是這些組的數量會很大,我會將這個查詢分成許多查詢,(如果這是在過濾器中使用 -OR 參數的限制,則每 50 個)
最后,命令將類似於:
Get-DistributionGroup -Filter "(Name like xyz) -or (Name like 'abc') or (Name like 'def')"
有人知道使用 - 或過濾器有任何限制嗎?
或者也許有更好的方法?
選項 1) 以編程方式構建過濾器
文檔沒有提到限制。 不過,自動創建過濾器並從文件或變量中檢索搜索詞會更容易:
# get the search values from a file or variable
$searchTerms = Get-Content "searchTerms.txt"
# OR define the values in your script
$searchTerms = "xyz", "abc", "def"
# build the filter
$filter = ($searchTerms | foreach {"(Name like '$_')"}) -join " -or "
Get-DistributionGroup -Filter $filter
選項 2) 分別按每個搜索詞過濾
拆分過濾器也是可能的,但您必須刪除重復項,如下所示:
$searchTerms | foreach {Get-DistributionGroup -Filter "(Name like '$_')"} | select -Unique
選項 3) 回退:查詢全部並進行自己的過濾
或者,您可以獲取所有通訊組並進行自己的過濾:
Get-DistributionGroup | where {
$name = $_.Name
return $null -ne $searchTerms.where({$name -like $_}, "First")
}
如果有人感興趣,有 250 個子過濾器的限制。 當發送到交換服務器的命令不會成功時,我已經設置了登錄服務器,並獲得了信息:
Call Site: SomeProject.PowerShell.Service.PowershellCommand`1.Execute
Exception Type:
Exception Message:
Stack Trace:
Additional Info: Could not invoke command Get-Group, Details:
The total number of explicit and implicit subfilters exceeds maximum allowed number of 250. Processing stopped.
“Details:”后面的內容是來自遠程交換服務器的消息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.