我在do-until块中使用以下内容循环,直到出现指定的Exchange Online迁移状态:
(Get-Migrationbatch -Identity $MigrationBatchName | Where {$_.Status -like "Completed" -or "CompletedWithErrors" -or "Corrupted" -or "Failed" -or "Stopped"})
但是,上述内容仍会返回状态为"同步"所以无论如何继续使用脚本。
我已尝试过-match,-eq但仍然相同。
我错过了什么?
答案 0 :(得分:9)
你必须这样写:
(Get-Migrationbatch -Identity $MigrationBatchName | Where {($_.Status -like "Completed") -or ($_.Status -like "CompletedWithErrors") -or ($_.Status -like "Corrupted") -or ($_.Status -like "Failed") -or ($_.Status -like "Stopped")})
这是另一种方法:
$valuesToLookFor = @(
'Completed',
'CompletedWithErrors',
'Corrupted',
'Failed',
'Stopped')
(Get-Migrationbatch -Identity $MigrationBatchName |
Where-Object { $valuesToLookFor -contains $_.Status })
答案 1 :(得分:0)
假设您不使用通配符,那么使用-in
运算符会更简单:
(Get-Migrationbatch -Identity $MigrationBatchName | Where Status -in "Completed","CompletedWithErrors","Corrupted","Failed","Stopped")
答案 2 :(得分:0)
另一个选择将过滤器数组转换为正则表达式字符串...
$filter_status = @("Completed", "CompletedWithErrors","Curropted","Failed", "Stopped")
(Get-Migrationbatch -Identity $MigrationBatchName | Where Status -Match ($filter_status -Join "|")