Powershell – Get-Migrationbatch – Return specific job with status

exchange-migrationmicrosoft-office-365powershell

I've created a PowerShell script that creates a migration batch from Exchange on-premises to O365 Exchange Online using the New-MigrationBatch cmdlet. My next step is to halt the script until the the migration batch has been completed using a do-while loop.

Using just the following will return jobs of the specified status but need to narrow this down to specify job name too in order to be able to complete the script.

Get-Migrationbatch -Status Completed

I've tried the following but not getting anything returned:

Get-Migrationbatch | Where {$_.Status -eq "Completed" -and $_.Identity -eq "TEST-O365Migration#1"}

I've also tried the following and get nothing

Get-Migrationbatch -Identity TEST-O365Migration#1 | Where {$_.Status -eq "Completed"}

However, when using -ne rather than -eq in the condition it returns the job specified but looks like it's ignoring the condition after the pipe as changing this to "Stopped" returns the same job regardless of status.

Any ideas?

Best Answer

Bah my mistake, Using -like rather than -eq provides the result I'm after. What a waste of time explaining my above predicament.