Updated Exchange 2013 provider to support litigation hold.
This version requires an updated configuration where the powershell remoting urls are required.
This commit is contained in:
parent
e3901f2440
commit
cfd6bc1629
4 changed files with 140 additions and 28 deletions
|
@ -162,7 +162,7 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
{
|
|
||||||
// skip execution if the current task is still running
|
// skip execution if the current task is still running
|
||||||
scheduledTasks = TaskManager.GetScheduledTasks();
|
scheduledTasks = TaskManager.GetScheduledTasks();
|
||||||
if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
|
if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
|
||||||
|
|
|
@ -74,6 +74,11 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
|
internal string PowerShellUrl
|
||||||
|
{
|
||||||
|
get { return ProviderSettings["PowerShellUrl"]; }
|
||||||
|
}
|
||||||
|
|
||||||
internal string RootOU
|
internal string RootOU
|
||||||
{
|
{
|
||||||
get { return ProviderSettings["RootOU"]; }
|
get { return ProviderSettings["RootOU"]; }
|
||||||
|
@ -1853,6 +1858,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
string ret = null;
|
string ret = null;
|
||||||
ExchangeTransaction transaction = StartTransaction();
|
ExchangeTransaction transaction = StartTransaction();
|
||||||
Runspace runSpace = null;
|
Runspace runSpace = null;
|
||||||
|
Runspace runSpaceEx = null;
|
||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
string id = null;
|
string id = null;
|
||||||
|
@ -1860,6 +1866,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runSpace = OpenRunspace();
|
runSpace = OpenRunspace();
|
||||||
|
runSpaceEx = OpenRunspaceEx();
|
||||||
Command cmd = null;
|
Command cmd = null;
|
||||||
Collection<PSObject> result = null;
|
Collection<PSObject> result = null;
|
||||||
|
|
||||||
|
@ -1947,7 +1954,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
cmd.Parameters.Add("Name", upn);
|
cmd.Parameters.Add("Name", upn);
|
||||||
cmd.Parameters.Add("InPlaceHoldEnabled", enabledLitigationHold);
|
cmd.Parameters.Add("InPlaceHoldEnabled", enabledLitigationHold);
|
||||||
cmd.Parameters.Add("SourceMailboxes", upn);
|
cmd.Parameters.Add("SourceMailboxes", upn);
|
||||||
ExecuteShellCommand(runSpace, cmd);
|
ExecuteShellCommandEx(runSpaceEx, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Client Access
|
//Client Access
|
||||||
|
@ -2258,9 +2265,11 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
ExchangeMailbox info = new ExchangeMailbox();
|
ExchangeMailbox info = new ExchangeMailbox();
|
||||||
info.AccountName = accountName;
|
info.AccountName = accountName;
|
||||||
Runspace runSpace = null;
|
Runspace runSpace = null;
|
||||||
|
Runspace runSpaceEx = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runSpace = OpenRunspace();
|
runSpace = OpenRunspace();
|
||||||
|
runSpaceEx = OpenRunspaceEx();
|
||||||
|
|
||||||
Collection<PSObject> result = GetMailboxObject(runSpace, accountName);
|
Collection<PSObject> result = GetMailboxObject(runSpace, accountName);
|
||||||
PSObject mailbox = result[0];
|
PSObject mailbox = result[0];
|
||||||
|
@ -2311,7 +2320,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
info.EnableLitigationHold = false;
|
info.EnableLitigationHold = false;
|
||||||
cmd = new Command("Get-MailboxSearch");
|
cmd = new Command("Get-MailboxSearch");
|
||||||
cmd.Parameters.Add("Identity", accountName);
|
cmd.Parameters.Add("Identity", accountName);
|
||||||
result = ExecuteShellCommand(runSpace, cmd);
|
result = ExecuteShellCommandEx(runSpaceEx, cmd);
|
||||||
if ((result != null) & (result.Count > 0))
|
if ((result != null) & (result.Count > 0))
|
||||||
{
|
{
|
||||||
mailbox = result[0];
|
mailbox = result[0];
|
||||||
|
@ -2483,9 +2492,11 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
ExchangeMailbox info = new ExchangeMailbox();
|
ExchangeMailbox info = new ExchangeMailbox();
|
||||||
info.AccountName = accountName;
|
info.AccountName = accountName;
|
||||||
Runspace runSpace = null;
|
Runspace runSpace = null;
|
||||||
|
Runspace runSpaceEx = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runSpace = OpenRunspace();
|
runSpace = OpenRunspace();
|
||||||
|
runSpaceEx = OpenRunspaceEx();
|
||||||
|
|
||||||
Collection<PSObject> result = GetMailboxObject(runSpace, accountName);
|
Collection<PSObject> result = GetMailboxObject(runSpace, accountName);
|
||||||
PSObject mailbox = result[0];
|
PSObject mailbox = result[0];
|
||||||
|
@ -2520,7 +2531,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
info.EnableLitigationHold = false;
|
info.EnableLitigationHold = false;
|
||||||
cmd = new Command("Get-MailboxSearch");
|
cmd = new Command("Get-MailboxSearch");
|
||||||
cmd.Parameters.Add("Identity", accountName);
|
cmd.Parameters.Add("Identity", accountName);
|
||||||
result = ExecuteShellCommand(runSpace, cmd);
|
result = ExecuteShellCommandEx(runSpaceEx, cmd);
|
||||||
if ((result != null) & (result.Count > 0))
|
if ((result != null) & (result.Count > 0))
|
||||||
{
|
{
|
||||||
mailbox = result[0];
|
mailbox = result[0];
|
||||||
|
@ -2574,9 +2585,11 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
ExchangeLog.DebugInfo("Account: {0}", accountName);
|
ExchangeLog.DebugInfo("Account: {0}", accountName);
|
||||||
|
|
||||||
Runspace runSpace = null;
|
Runspace runSpace = null;
|
||||||
|
Runspace runSpaceEx = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runSpace = OpenRunspace();
|
runSpace = OpenRunspace();
|
||||||
|
runSpaceEx = OpenRunspaceEx();
|
||||||
|
|
||||||
|
|
||||||
Command cmd = new Command("Set-Mailbox");
|
Command cmd = new Command("Set-Mailbox");
|
||||||
|
@ -2600,12 +2613,12 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
//LitigationHold
|
//LitigationHold
|
||||||
cmd = new Command("Get-MailboxSearch");
|
cmd = new Command("Get-MailboxSearch");
|
||||||
cmd.Parameters.Add("Identity", accountName);
|
cmd.Parameters.Add("Identity", accountName);
|
||||||
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);
|
Collection<PSObject> result = ExecuteShellCommandEx(runSpaceEx, cmd);
|
||||||
cmd = new Command((result == null) || (result.Count == 0) ? "New-MailboxSearch" : "Set-MailboxSearch");
|
cmd = new Command((result == null) || (result.Count == 0) ? "New-MailboxSearch" : "Set-MailboxSearch");
|
||||||
cmd.Parameters.Add((result == null) || (result.Count == 0) ? "Name" : "Identity", accountName);
|
cmd.Parameters.Add((result == null) || (result.Count == 0) ? "Name" : "Identity", accountName);
|
||||||
cmd.Parameters.Add("InPlaceHoldEnabled", enabledLitigationHold);
|
cmd.Parameters.Add("InPlaceHoldEnabled", enabledLitigationHold);
|
||||||
cmd.Parameters.Add("SourceMailboxes", accountName);
|
cmd.Parameters.Add("SourceMailboxes", accountName);
|
||||||
ExecuteShellCommand(runSpace, cmd);
|
ExecuteShellCommandEx(runSpaceEx, cmd);
|
||||||
|
|
||||||
//Client Access
|
//Client Access
|
||||||
cmd = new Command("Set-CASMailbox");
|
cmd = new Command("Set-CASMailbox");
|
||||||
|
@ -2971,9 +2984,11 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
|
|
||||||
ExchangeMailboxStatistics info = new ExchangeMailboxStatistics();
|
ExchangeMailboxStatistics info = new ExchangeMailboxStatistics();
|
||||||
Runspace runSpace = null;
|
Runspace runSpace = null;
|
||||||
|
Runspace runSpaceEx = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
runSpace = OpenRunspace();
|
runSpace = OpenRunspace();
|
||||||
|
runSpaceEx = OpenRunspaceEx();
|
||||||
|
|
||||||
Collection<PSObject> result = GetMailboxObject(runSpace, id);
|
Collection<PSObject> result = GetMailboxObject(runSpace, id);
|
||||||
PSObject mailbox = result[0];
|
PSObject mailbox = result[0];
|
||||||
|
@ -3008,7 +3023,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
info.LitigationHoldEnabled = false;
|
info.LitigationHoldEnabled = false;
|
||||||
cmd = new Command("Get-MailboxSearch");
|
cmd = new Command("Get-MailboxSearch");
|
||||||
cmd.Parameters.Add("Identity", id);
|
cmd.Parameters.Add("Identity", id);
|
||||||
result = ExecuteShellCommand(runSpace, cmd);
|
result = ExecuteShellCommandEx(runSpaceEx, cmd);
|
||||||
if ((result != null) & (result.Count > 0))
|
if ((result != null) & (result.Count > 0))
|
||||||
{
|
{
|
||||||
mailbox = result[0];
|
mailbox = result[0];
|
||||||
|
@ -5828,26 +5843,8 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region PowerShell integration
|
#region PowerShell integration
|
||||||
/*private Collection<PSObject> ExecuteShellCommand2(Runspace runSpace, string cmd)
|
|
||||||
{
|
|
||||||
ExchangeLog.LogStart("ExecuteShellCommand");
|
|
||||||
RunspaceInvoke invoker = new RunspaceInvoke(runSpace);
|
|
||||||
System.Collections.IList errors = null;
|
|
||||||
Collection<PSObject> results = invoker.Invoke(cmd, null, out errors);
|
|
||||||
if (errors != null && errors.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (PSObject err in errors)
|
|
||||||
{
|
|
||||||
string errorMessage = string.Format("Invoke error: {0}", err.ToString());
|
|
||||||
ExchangeLog.LogError(errorMessage, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
invoker = null;
|
|
||||||
ExchangeLog.LogEnd("ExecuteShellCommand");
|
|
||||||
return results;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private static RunspaceConfiguration runspaceConfiguration = null;
|
private static RunspaceConfiguration runspaceConfiguration = null;
|
||||||
|
private static WSManConnectionInfo connectionInfo = null;
|
||||||
private static string ExchangePath = null;
|
private static string ExchangePath = null;
|
||||||
|
|
||||||
internal static string GetExchangePath()
|
internal static string GetExchangePath()
|
||||||
|
@ -5919,6 +5916,35 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
return runSpace;
|
return runSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal virtual Runspace OpenRunspaceEx()
|
||||||
|
{
|
||||||
|
ExchangeLog.LogStart("OpenRunspace Ex");
|
||||||
|
ExchangeLog.DebugInfo("PowerShelll Url: {0}", PowerShellUrl);
|
||||||
|
|
||||||
|
if (connectionInfo == null)
|
||||||
|
{
|
||||||
|
PSCredential credential = (PSCredential)null;
|
||||||
|
|
||||||
|
connectionInfo = new WSManConnectionInfo(new Uri(PowerShellUrl),
|
||||||
|
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
|
||||||
|
credential);
|
||||||
|
|
||||||
|
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.NegotiateWithImplicitCredential;
|
||||||
|
}
|
||||||
|
|
||||||
|
Runspace runSpace = RunspaceFactory.CreateRunspace(connectionInfo);
|
||||||
|
|
||||||
|
runSpace.Open();
|
||||||
|
|
||||||
|
ExchangeLog.LogEnd("OpenRunspace");
|
||||||
|
|
||||||
|
Command cmd = new Command("Set-ADServerSettings");
|
||||||
|
cmd.Parameters.Add("PreferredServer", PrimaryDomainController);
|
||||||
|
ExecuteShellCommand(runSpace, cmd, false);
|
||||||
|
return runSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal void CloseRunspace(Runspace runspace)
|
internal void CloseRunspace(Runspace runspace)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -5934,6 +5960,23 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void CloseRunspaceEx(Runspace runspace)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (runspace != null && runspace.RunspaceStateInfo.State == RunspaceState.Opened)
|
||||||
|
{
|
||||||
|
runspace.Dispose();
|
||||||
|
runspace = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExchangeLog.LogError("Runspace error", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd)
|
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd)
|
||||||
{
|
{
|
||||||
return ExecuteShellCommand(runSpace, cmd, true);
|
return ExecuteShellCommand(runSpace, cmd, true);
|
||||||
|
@ -5995,6 +6038,73 @@ namespace WebsitePanel.Providers.HostedSolution
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal Collection<PSObject> ExecuteShellCommandEx(Runspace runSpace, Command cmd)
|
||||||
|
{
|
||||||
|
return ExecuteShellCommandEx(runSpace, cmd, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Collection<PSObject> ExecuteShellCommandEx(Runspace runSpace, Command cmd, bool useDomainController)
|
||||||
|
{
|
||||||
|
object[] errors;
|
||||||
|
return ExecuteShellCommandEx(runSpace, cmd, useDomainController, out errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Collection<PSObject> ExecuteShellCommandEx(Runspace runSpace, Command cmd, out object[] errors)
|
||||||
|
{
|
||||||
|
return ExecuteShellCommandEx(runSpace, cmd, true, out errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Collection<PSObject> ExecuteShellCommandEx(Runspace runSpace, Command cmd, bool useDomainController, out object[] errors)
|
||||||
|
{
|
||||||
|
ExchangeLog.LogStart("ExecuteShellCommandEx");
|
||||||
|
List<object> errorList = new List<object>();
|
||||||
|
|
||||||
|
if (useDomainController)
|
||||||
|
{
|
||||||
|
CommandParameter dc = new CommandParameter("DomainController", PrimaryDomainController);
|
||||||
|
if (!cmd.Parameters.Contains(dc))
|
||||||
|
{
|
||||||
|
cmd.Parameters.Add(dc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ExchangeLog.DebugCommand(cmd);
|
||||||
|
Collection<PSObject> results = null;
|
||||||
|
// Create a pipeline
|
||||||
|
Pipeline pipeLine = runSpace.CreatePipeline();
|
||||||
|
using (pipeLine)
|
||||||
|
{
|
||||||
|
// Add the command
|
||||||
|
pipeLine.Commands.Add(cmd);
|
||||||
|
// Execute the pipeline and save the objects returned.
|
||||||
|
results = pipeLine.Invoke();
|
||||||
|
|
||||||
|
// Log out any errors in the pipeline execution
|
||||||
|
// NOTE: These errors are NOT thrown as exceptions!
|
||||||
|
// Be sure to check this to ensure that no errors
|
||||||
|
// happened while executing the command.
|
||||||
|
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
|
||||||
|
{
|
||||||
|
var error = pipeLine.Error.Read() as Collection<ErrorRecord>;
|
||||||
|
if (error != null)
|
||||||
|
{
|
||||||
|
foreach (ErrorRecord er in error)
|
||||||
|
{
|
||||||
|
errorList.Add(er);
|
||||||
|
string errorMessage = string.Format("Invoke error: {0}", er.Exception.Message);
|
||||||
|
ExchangeLog.LogWarning(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pipeLine = null;
|
||||||
|
errors = errorList.ToArray();
|
||||||
|
ExchangeLog.LogEnd("ExecuteShellCommandEx");
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the distinguished name of the object from the shell execution result
|
/// Returns the distinguished name of the object from the shell execution result
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<!-- Display Settings -->
|
<!-- Display Settings -->
|
||||||
<PortalName>WebsitePanel</PortalName>
|
<PortalName>WebsitePanel</PortalName>
|
||||||
<!-- Enterprise Server -->
|
<!-- Enterprise Server -->
|
||||||
<EnterpriseServer>http://hstprov01.hosting.local:9002</EnterpriseServer>
|
<EnterpriseServer>http://localhost:9002</EnterpriseServer>
|
||||||
<!-- General Settings -->
|
<!-- General Settings -->
|
||||||
<CultureCookieName>UserCulture</CultureCookieName>
|
<CultureCookieName>UserCulture</CultureCookieName>
|
||||||
<ThemeCookieName>UserTheme</ThemeCookieName>
|
<ThemeCookieName>UserTheme</ThemeCookieName>
|
||||||
|
|
|
@ -224,7 +224,9 @@
|
||||||
<Content Include="App_Data\ModulesData.config">
|
<Content Include="App_Data\ModulesData.config">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="App_Data\SiteSettings.config" />
|
<Content Include="App_Data\SiteSettings.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</Content>
|
||||||
<None Include="App_Data\SupportedThemes.config" />
|
<None Include="App_Data\SupportedThemes.config" />
|
||||||
<None Include="App_Data\Countries.config" />
|
<None Include="App_Data\Countries.config" />
|
||||||
<None Include="App_Data\CountryStates.config" />
|
<None Include="App_Data\CountryStates.config" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue