daysey, after a little tweaking to support my environment your script worked a treat. Props, friend! I truly appreciate you sharing.
Still fighting with the OAuth errors a number of folks have experienced. I found that the OAuthApplicationId for my OrganizationRelationship was blank, so I set it to match the ApplicationId in my MigrationEndpoint.
Error: MigrationTransientException: The call to 'https://bn6pr0101mb2945.prod.exchangelabs.com/mrs/Microsoft.Exchange.MailboxReplicationService.ProxyService/OAuth' failed. Error details: Access is denied.. --> The call to 'https://bn6pr0101mb2945.prod.exchangelabs.com/mrs/Microsoft.Exchange.MailboxReplicationService.ProxyService/OAuth' failed. Error details: Access is denied.. --> Access is denied.