Fixed: When deleting an exchange user the operations failed with "Cannot delete
object when there are leaf objects Ensure activesync devices are removed before deleting or disabling a mailbox
This commit is contained in:
parent
12d0e687f1
commit
0ecd34363a
2 changed files with 54 additions and 0 deletions
|
@ -467,6 +467,9 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
try
|
||||
{
|
||||
runSpace = OpenRunspace();
|
||||
|
||||
RemoveDevicesInternal(runSpace, id);
|
||||
|
||||
Command cmd = new Command("Disable-Mailbox");
|
||||
cmd.Parameters.Add("Identity", id);
|
||||
cmd.Parameters.Add("Confirm", false);
|
||||
|
@ -1087,6 +1090,8 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
try
|
||||
{
|
||||
id = ObjToString(GetPSObjectProperty(obj, "Identity"));
|
||||
RemoveDevicesInternal(runSpace, id);
|
||||
|
||||
RemoveMailbox(runSpace, id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -2063,6 +2068,8 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
{
|
||||
runSpace = OpenRunspace();
|
||||
|
||||
RemoveDevicesInternal(runSpace, accountName);
|
||||
|
||||
RemoveMailbox(runSpace, accountName);
|
||||
}
|
||||
finally
|
||||
|
@ -6296,6 +6303,48 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
ExchangeLog.LogEnd("CancelRemoteWipeRequestInternal");
|
||||
}
|
||||
|
||||
|
||||
internal void RemoveDevicesInternal(Runspace runSpace, string accountName)
|
||||
{
|
||||
ExchangeLog.LogStart("RemoveDevicesInternal");
|
||||
ExchangeLog.DebugInfo("Account name: {0}", accountName);
|
||||
|
||||
try
|
||||
{
|
||||
runSpace = OpenRunspace();
|
||||
Command cmd = new Command("Get-ActiveSyncDeviceStatistics");
|
||||
cmd.Parameters.Add("Mailbox", accountName);
|
||||
|
||||
Collection<PSObject> result = null;
|
||||
try
|
||||
{
|
||||
result = ExecuteShellCommand(runSpace, cmd);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
foreach (PSObject obj in result)
|
||||
{
|
||||
ExchangeMobileDevice device = GetMobileDeviceObject(obj);
|
||||
|
||||
cmd = new Command("Remove-ActiveSyncDevice");
|
||||
cmd.Parameters.Add("Identity", device.DeviceID);
|
||||
cmd.Parameters.Add("Confirm", false);
|
||||
ExecuteShellCommand(runSpace, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
ExchangeLog.LogEnd("RemoveDevicesInternal");
|
||||
}
|
||||
|
||||
|
||||
private void RemoveDeviceInternal(string id)
|
||||
{
|
||||
ExchangeLog.LogStart("RemoveDeviceInternal");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue