TenantOrganizationPresentationObjectWrapper IOrganizationOperation.GetOrganization(string tenantId) { TenantOrganizationPresentationObjectWrapper result; using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers")) { PSCommand pscommand = new PSCommand(); pscommand.AddCommand("Get-Organization"); pscommand.AddParameter("Identity", tenantId); TenantOrganizationPresentationObject tenant = null; try { tenant = anchorRunspaceProxy.RunPSCommandSingleOrDefault <TenantOrganizationPresentationObject>(pscommand); } catch (Exception ex) { this.Context.Logger.Log(MigrationEventType.Error, "MigrationPermanentException from GetOrganization '{0}'.{1}", new object[] { tenantId, ex }); if (ex.InnerException is ManagementObjectNotFoundException) { throw new OrganizationNotFoundException(tenantId, ex); } throw; } result = new TenantOrganizationPresentationObjectWrapper(tenant); } return(result); }
RecipientWrapper IOrganizationOperation.GetUser(string organizationId, string userId) { RecipientWrapper result; using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers")) { PSCommand pscommand = new PSCommand(); pscommand.AddCommand("Get-User"); pscommand.AddParameter("Organization", organizationId); pscommand.AddParameter("Identity", userId); User user; try { user = anchorRunspaceProxy.RunPSCommandSingleOrDefault <User>(pscommand); } catch (Exception ex) { this.Context.Logger.Log(MigrationEventType.Error, "MigrationPermanentException from GetUser '{0}'.{1}", new object[] { userId, ex }); if (ex.InnerException is ManagementObjectNotFoundException) { throw new UserNotFoundException(userId, ex.InnerException); } throw; } result = new RecipientWrapper(user); } return(result); }
bool IOrganizationOperation.TryGetAnchorMailbox(string tenantId, out RecipientWrapper anchorMailbox) { anchorMailbox = null; bool result; using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers")) { PSCommand pscommand = new PSCommand(); pscommand.AddCommand("Get-Mailbox"); pscommand.AddParameter("Arbitration"); pscommand.AddParameter("Organization", tenantId); pscommand.AddParameter("Identity", "Migration.8f3e7716-2011-43e4-96b1-aba62d229136"); Mailbox mailbox; try { mailbox = anchorRunspaceProxy.RunPSCommandSingleOrDefault <Mailbox>(pscommand); if (mailbox == null) { this.Context.Logger.Log(MigrationEventType.Error, "Get-AnchorMailbox for '{0}' returned null", new object[0]); return(false); } } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException is ManagementObjectNotFoundException) { this.Context.Logger.Log(MigrationEventType.Information, "Get-AnchorMailbox for '{0}' failed due to: {1}", new object[] { tenantId, ex.InnerException }); return(false); } this.Context.Logger.Log(MigrationEventType.Error, "Get-AnchorMailbox for '{0}' failed due to: {1}", new object[] { tenantId, ex }); throw; } anchorMailbox = new RecipientWrapper(mailbox); result = true; } return(result); }
bool IOrganizationOperation.TryRemoveMoveRequest(string identity) { using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers")) { PSCommand pscommand = new PSCommand(); pscommand.AddCommand("Remove-MoveRequest"); pscommand.AddParameter("Identity", identity); pscommand.AddParameter("Confirm", false); try { anchorRunspaceProxy.RunPSCommandSingleOrDefault <object>(pscommand); } catch (MigrationPermanentException ex) { this.Context.Logger.Log(MigrationEventType.Error, "Remove-MoveRequest for '{0}' failed due to: {1}", new object[] { identity, ex }); return(false); } } return(true); }
void IOrganizationOperation.CreateAnchorMailbox(string tenantId) { using (AnchorRunspaceProxy anchorRunspaceProxy = AnchorRunspaceProxy.CreateRunspaceForDatacenterAdmin(this.Context, "upgradehandlers")) { PSCommand pscommand = new PSCommand(); pscommand.AddCommand("New-Mailbox"); pscommand.AddParameter("Arbitration"); pscommand.AddParameter("Organization", tenantId); pscommand.AddParameter("Name", "Migration.8f3e7716-2011-43e4-96b1-aba62d229136"); pscommand.AddParameter("DisplayName", "Microsoft Exchange Migration"); pscommand.AddParameter("UserPrincipalName", "Migration.8f3e7716-2011-43e4-96b1-aba62d229136@" + tenantId); pscommand.AddParameter("OverrideRecipientQuotas"); Mailbox mailbox; try { mailbox = anchorRunspaceProxy.RunPSCommandSingleOrDefault <Mailbox>(pscommand); } catch (MigrationPermanentException ex) { this.Context.Logger.Log(MigrationEventType.Error, "Unable to create Migration Mailbox for organization '{0}': {1}", new object[] { tenantId, ex }); throw; } pscommand = new PSCommand(); pscommand.AddCommand("Set-Mailbox"); pscommand.AddParameter("Identity", mailbox.Identity); pscommand.AddParameter("Arbitration"); pscommand.AddParameter("ProhibitSendReceiveQuota", "10GB"); pscommand.AddParameter("ProhibitSendQuota", "10GB"); pscommand.AddParameter("IssueWarningQuota", "9GB"); pscommand.AddParameter("RecoverableItemsQuota", "30GB"); pscommand.AddParameter("RecoverableItemsWarningQuota", "20GB"); pscommand.AddParameter("UseDatabaseQuotaDefaults", false); pscommand.AddParameter("SCLDeleteEnabled", false); pscommand.AddParameter("SCLJunkEnabled", false); pscommand.AddParameter("SCLQuarantineEnabled", false); pscommand.AddParameter("SCLRejectEnabled", false); pscommand.AddParameter("HiddenFromAddressListsEnabled", true); pscommand.AddParameter("Management", true); pscommand.AddParameter("Force"); pscommand.AddParameter("TenantUpgrade", true); int config = this.Context.Config.GetConfig <int>("NumberOfSetMailboxAttempts"); int config2 = this.Context.Config.GetConfig <int>("SetMailboxAttemptIntervalSeconds"); for (int i = 1; i <= config; i++) { try { anchorRunspaceProxy.RunPSCommand <Mailbox>(pscommand); break; } catch (MigrationPermanentException ex2) { this.Context.Logger.Log(MigrationEventType.Warning, "Unable to set defaults for anchor Mailbox for organization '{0}' after {1} attempt(s): {2}", new object[] { config, tenantId, ex2 }); if (i >= config) { this.Context.Logger.Log(MigrationEventType.Error, "Gving up attempts to set defaults for anchor Mailbox for organization '{0}': {1}", new object[] { tenantId, ex2 }); throw; } Thread.Sleep(config2 * 1000); } } } }