private void GetExchangePrincipal(IRecipientSession recipientSession) { Exception ex = null; if (this.Mailbox != null) { this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, this.Mailbox, "Get-MobileDeviceStatistics", out ex); } else if (this.Identity != null) { TIdentity identity = this.Identity; MailboxIdParameter mailboxId = identity.GetMailboxId(); if (mailboxId == null && this.DataObject != null) { this.Identity = (TIdentity)((object)this.CreateIdentityObject()); TIdentity identity2 = this.Identity; mailboxId = identity2.GetMailboxId(); } if (mailboxId == null) { TIdentity identity3 = this.Identity; base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(identity3.ToString())), ErrorCategory.InvalidArgument, null); } this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, mailboxId, base.CommandRuntime.ToString(), out ex); } if (ex != null) { base.WriteError(ex, ErrorCategory.InvalidArgument, null); } }
protected override void InternalValidate() { MailboxIdParameter mailboxIdParameter = null; try { base.InternalValidate(); } catch (ManagementObjectNotFoundException) { if (this.Identity == null || !this.TryGetMailboxIdFromIdentity(this.Identity.ToString(), out mailboxIdParameter)) { throw; } this.deviceExistsinAD = false; } if (base.HasErrors) { return; } if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings)) { ADObjectId adobjectId; if (!base.TryGetExecutingUserId(out adobjectId)) { throw new ExecutingUserPropertyNotFoundException("executingUserid"); } if (!base.DataObject.Id.Parent.Parent.Equals(adobjectId) || (mailboxIdParameter != null && !mailboxIdParameter.Equals(adobjectId))) { base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null); } } Exception ex = null; if (mailboxIdParameter == null) { mailboxIdParameter = this.Identity.GetMailboxId(); } if (mailboxIdParameter == null && base.DataObject != null) { this.Identity = new MobileDeviceIdParameter(base.DataObject); mailboxIdParameter = this.Identity.GetMailboxId(); } if (mailboxIdParameter == null) { base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null); } this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, this.CreateTenantGlobalCatalogSession(base.SessionSettings), mailboxIdParameter, "Remove-MobileDevice", out ex); if (ex != null) { base.WriteError(ex, ErrorCategory.InvalidArgument, null); } if (DeviceInfo.IsThrottlingLimitsExceeded((IConfigurationSession)base.DataSession, this.principal, out this.activeSyncDevices)) { uint maxDeviceDeleteCount = 0U; using (IBudget budget = StandardBudget.Acquire(this.principal.Sid, BudgetType.Eas, this.principal.MailboxInfo.OrganizationId.ToADSessionSettings())) { IThrottlingPolicy throttlingPolicy = budget.ThrottlingPolicy; maxDeviceDeleteCount = throttlingPolicy.EasMaxDeviceDeletesPerMonth.Value; } base.WriteError(new LocalizedException(Strings.MaxDeviceDeletesPerMonthReached(this.activeSyncDevices.ObjectsDeletedThisPeriod, maxDeviceDeleteCount)), ErrorCategory.WriteError, null); } }
internal static ExchangePrincipal GetExchangePrincipal(ADSessionSettings sessionSettings, IRecipientSession recipientSession, MailboxIdParameter mailbox, string cmdletName, out Exception localizedError) { ADUser aduser = null; return(MobileDeviceTaskHelper.GetExchangePrincipal(sessionSettings, recipientSession, mailbox, cmdletName, out localizedError, out aduser)); }
protected override void InternalValidate() { TaskLogger.LogEnter(); try { base.InternalValidate(); if (!base.HasErrors) { if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings)) { ADObjectId id; if (!base.TryGetExecutingUserId(out id)) { throw new ExecutingUserPropertyNotFoundException("executingUserid"); } if (!this.DataObject.Id.Parent.Parent.Equals(id)) { base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null); } } IRecipientSession recipientSession = this.CreateTenantGlobalCatalogSession(base.SessionSettings); Exception ex = null; MailboxIdParameter mailboxId = this.Identity.GetMailboxId(); if (mailboxId == null && this.DataObject != null) { this.Identity = new MobileDeviceIdParameter(this.DataObject); mailboxId = this.Identity.GetMailboxId(); } if (mailboxId == null) { base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null); } ADUser adObject = null; this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, mailboxId, "Clear-MobileDevice", out ex, out adObject); if (ex != null) { base.WriteError(ex, ErrorCategory.InvalidArgument, null); } IList <LocalizedString> list = null; ADObjectId adobjectId = null; base.TryGetExecutingUserId(out adobjectId); this.validatedAddresses = MobileDeviceTaskHelper.ValidateAddresses(recipientSession, adobjectId, this.NotificationEmailAddresses, out list); if (list != null) { foreach (LocalizedString text in list) { this.WriteWarning(text); } } base.VerifyIsWithinScopes((IDirectorySession)base.DataSession, adObject, true, new DataAccessTask <MobileDevice> .ADObjectOutOfScopeString(Strings.ErrorCannotChangeMailboxOutOfWriteScope)); if (adobjectId != null) { ExchangePrincipal exchangePrincipal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, new MailboxIdParameter(adobjectId), "Clear-MobileDevice", out ex); if (ex != null) { base.WriteWarning(ex.ToString()); } if (exchangePrincipal != null) { this.wipeRequestorSMTP = exchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(); } else { this.wipeRequestorSMTP = null; } } } } finally { TaskLogger.LogExit(); } }