本文整理汇总了C#中PowerShell.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.Dispose方法的具体用法?C# PowerShell.Dispose怎么用?C# PowerShell.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PowerShell
的用法示例。
在下文中一共展示了PowerShell.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Disable_Company
//.........这里部分代码省略.........
powershell.Invoke();
this.logger.Info("Deleted conference room list for " + companyCode);
// Check for errors
CheckErrors(ref powershell, true);
//
// Delete Contact Address List
//
cmd = new PSCommand();
cmd.AddCommand("Remove-AddressList");
cmd.AddParameter("Identity", companyCode + " - All Contacts");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
this.logger.Info("Deleted all contacts list for " + companyCode);
// Check for errors
CheckErrors(ref powershell, true);
//
// Delete Group Address List
//
cmd = new PSCommand();
cmd.AddCommand("Remove-AddressList");
cmd.AddParameter("Identity", companyCode + " - All Groups");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
this.logger.Info("Deleted all groups list for " + companyCode);
// Check for errors
CheckErrors(ref powershell, true);
//
// Delete Users list
//
cmd = new PSCommand();
cmd.AddCommand("Remove-AddressList");
cmd.AddParameter("Identity", companyCode + " - All Users");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
this.logger.Info("Deleted all users list for " + companyCode);
// Check for errors
CheckErrors(ref powershell, true);
//
// Delete Global Address List
//
cmd = new PSCommand();
cmd.AddCommand("Remove-GlobalAddressList");
cmd.AddParameter("Identity", companyCode + " - GAL");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
this.logger.Info("Deleted global address list for " + companyCode);
// Check for errors
CheckErrors(ref powershell, true);
//
// Delete all accepted domains
//
foreach (string d in domains)
{
cmd = new PSCommand();
cmd.AddCommand("Remove-AcceptedDomain");
cmd.AddParameter("Identity", d);
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
this.logger.Info("Deleted accepted domain for " + companyCode);
// Check for errors
CheckErrors(ref powershell, true);
}
// Stop the clock
stopwatch.Stop();
// INFO //
logger.Info("Successfully disabled Exchange for company " + companyCode + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception)
{
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
开发者ID:KnowMoreIT,项目名称:CloudPanel_3.0,代码行数:101,代码来源:ExchCmds+(DXN-PC's+conflicted+copy+2013-11-01).cs
示例2: Enable_Mailbox
/// <summary>
/// Enables a user for a mailbox
/// </summary>
/// <param name="userPrincipalName"></param>
/// <param name="companyCode"></param>
/// <param name="email"></param>
/// <param name="quotaWarning"></param>
/// <param name="quotaProhibitSend"></param>
/// <param name="quotaProhibitSendReceive"></param>
/// <param name="maxReceiveSize"></param>
/// <param name="maxSendSize"></param>
/// <param name="recipientLimit"></param>
/// <param name="retainDeletedItems"></param>
/// <param name="activeSyncEnabled"></param>
/// <param name="ecpEnabled"></param>
/// <param name="imapEnabled"></param>
/// <param name="mapiEnabled"></param>
/// <param name="owaEnabled"></param>
/// <param name="popEnabled"></param>
public void Enable_Mailbox(string userPrincipalName, string companyCode, string email, int quotaWarning, int quotaProhibitSend, int quotaProhibitSendReceive,
int maxReceiveSize, int maxSendSize, int recipientLimit, int retainDeletedItems, bool activeSyncEnabled, bool ecpEnabled, bool imapEnabled, bool mapiEnabled,
bool owaEnabled, bool popEnabled, string activeSyncPolicyName = null)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Enabling mailbox for user [" + userPrincipalName + "] for company code " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Enable the mailbox
PSCommand cmd = new PSCommand();
cmd.AddCommand("Enable-Mailbox");
cmd.AddParameter("Identity", userPrincipalName);
cmd.AddParameter("AddressBookPolicy", companyCode + " ABP");
cmd.AddParameter("PrimarySmtpAddress", email);
cmd.AddParameter("Alias", email.Replace("@", "_"));
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// Dispose of Powershell
powershell.Dispose();
// Set the details
Set_Mailbox(userPrincipalName, quotaWarning, maxReceiveSize, maxSendSize, companyCode, quotaProhibitSend, quotaProhibitSendReceive, recipientLimit, retainDeletedItems);
// Set more details using CAS Mailbox
Set_CASMailbox(userPrincipalName, companyCode, activeSyncEnabled, ecpEnabled, imapEnabled, mapiEnabled, owaEnabled, popEnabled, activeSyncPolicyName);
// DEBUG //
logger.Debug("Successfully enabled mailbox for [" + userPrincipalName + "] for company code " + companyCode + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception ex)
{
// Do not throw error if it already exists
if (!ex.ToString().Contains("already exists"))
throw;
else
this.logger.Info("Powershell error was thrown because the mailbox already existed. Continuing without error.");
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例3: ExecuteHelper
/// <summary>
/// A helper class that builds and executes a pipeline that writes
/// to the default output path. Any exceptions that are thrown are
/// just passed to the caller. Since all output goes to the default
/// outter, this method does not return anything.
/// </summary>
/// <param name="cmd">The script to run.</param>
/// <param name="input">
/// Any input arguments to pass to the script.
/// If null then nothing is passed in.
/// </param>
private void ExecuteHelper(string cmd, object input)
{
// Ignore empty command lines.
if (String.IsNullOrEmpty(cmd))
{
return;
}
// Create the pipeline object and make it available to the
// ctrl-C handle through the currentPowerShell instance
// variable.
lock (_instanceLock)
{
_currentPowerShell = PowerShell.Create();
}
// Add a script and command to the pipeline and then run the pipeline. Place
// the results in the currentPowerShell variable so that the pipeline can be
// stopped.
try
{
_currentPowerShell.Runspace = _runspace;
_currentPowerShell.AddScript(cmd);
// Add the default outputter to the end of the pipe and then call the
// MergeMyResults method to merge the output and error streams from the
// pipeline. This will result in the output being written using the PSHost
// and PSHostUserInterface classes instead of returning objects to the host
// application.
_currentPowerShell.AddCommand("out-default");
_currentPowerShell.Commands.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
// If there is any input pass it in, otherwise just invoke the
// the pipeline.
if (input != null)
{
_currentPowerShell.Invoke(new[] {input});
}
else
{
_currentPowerShell.Invoke();
}
}
finally
{
// Dispose the PowerShell object and set currentPowerShell to null.
// It is locked because currentPowerShell may be accessed by the
// ctrl-C handler.
lock (_instanceLock)
{
_currentPowerShell.Dispose();
_currentPowerShell = null;
}
}
}
示例4: New_OfflineAddressBook
/// <summary>
/// Creates a new offline address book for a specific company
/// </summary>
/// <param name="companyCode">Company Code to create the OAB for</param>
/// <param name="groupAllowedToDownload">Group granted rights to download OAB</param>
public void New_OfflineAddressBook(string companyCode, string groupAllowedToDownload)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Creating new offline address book for company code " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
PSCommand cmd = new PSCommand();
cmd.AddCommand("New-OfflineAddressBook");
cmd.AddParameter("Name", companyCode + " OAL");
cmd.AddParameter("AddressLists", companyCode + " GAL");
cmd.AddParameter("DomainController", domainController);
cmd.AddCommand("Add-ADPermission");
cmd.AddParameter("User", groupAllowedToDownload.Replace(" ", string.Empty));
cmd.AddParameter("ExtendedRights", "MS-EXCH-DOWNLOAD-OAB");
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// DEBUG //
logger.Debug("Successfully created new offline address book for company code " + companyCode + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception ex)
{
// Do not throw error if it already exists
if (!ex.ToString().Contains("already exists"))
throw;
else
this.logger.Info("Powershell error was thrown because the offline address book already existed. Continuing without error.");
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例5: New_AddressList
/// <summary>
/// Creates a new address list for a specific company
/// </summary>
/// <param name="companyCode">CompanyCode to create address list for</param>
/// <param name="addrType">Type of address list to add</param>
public void New_AddressList(string companyCode, AddressListType addrType)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Creating new address list [" + addrType.ToString() + "] for company code " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Figure out what address list we are creating
string recipientFilter = string.Empty;
string addressListName = string.Empty;
switch (addrType)
{
case AddressListType.ConferenceRoomMailbox:
recipientFilter = string.Format(@"((Alias -ne $null) -and (CustomAttribute1 -eq '{0}') -and (((RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox'))))", companyCode);
addressListName = string.Format("{0} - {1}", companyCode, "All Rooms");
break;
case AddressListType.User:
recipientFilter = string.Format(@"((Alias -ne $null) -and (CustomAttribute1 -eq '{0}') -and (((((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (-not(Database -ne $null)) -and (-not(ServerLegacyDN -ne $null)))) -or (((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (((Database -ne $null) -or (ServerLegacyDN -ne $null))))))))", companyCode);
addressListName = string.Format("{0} - {1}", companyCode, "All Users");
break;
case AddressListType.Contact:
recipientFilter = string.Format(@"((Alias -ne $null) -and (CustomAttribute1 -eq '{0}') -and (((ObjectCategory -like 'person') -and (ObjectClass -eq 'contact'))))", companyCode);
addressListName = string.Format("{0} - {1}", companyCode, "All Contacts");
break;
case AddressListType.Group:
recipientFilter = string.Format(@"((Alias -ne $null) -and (CustomAttribute1 -eq '{0}') -and (ObjectCategory -like 'group'))", companyCode);
addressListName = string.Format("{0} - {1}", companyCode, "All Groups");
break;
default:
throw new Exception("Invalid address list type was supplied. Supplied value: " + addrType.ToString());
}
PSCommand cmd = new PSCommand();
cmd.AddCommand("New-AddressList");
cmd.AddParameter("Name", addressListName);
cmd.AddParameter("RecipientFilter", recipientFilter);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// DEBUG //
logger.Debug("Successfully created new address list [" + addrType.ToString() + "] for company code " + companyCode + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception ex)
{
// Do not throw error if it already exists
if (!ex.ToString().Contains("already exists"))
throw;
else
this.logger.Info("Powershell error was thrown because the address list already existed. Continuing without error.");
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例6: Remove_Contact
/// <summary>
/// Removes a mail contact from Exchange
/// </summary>
/// <param name="distinguishedName"></param>
public void Remove_Contact(string distinguishedName)
{
try
{
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// INFO //
this.logger.Info("Deleting contact " + distinguishedName + " from Exchange");
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
PSCommand cmd = new PSCommand();
cmd.AddCommand("Remove-MailContact");
cmd.AddParameter("Identity", distinguishedName);
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// INFO //
this.logger.Info("Successfully deleted contact " + distinguishedName + " from Exchange in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception ex)
{
// Do not throw error if it cannot be found
if (!ex.ToString().Contains("couldn't be found on"))
{
// FATAL //
this.logger.Fatal("Failed to delete contact " + distinguishedName + " from Exchange.", ex);
throw;
}
else
this.logger.Info("Powershell error was thrown because the contact does not exist in Exchange. Continuing without error.");
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例7: Remove_AcceptedDomain
/// <summary>
/// Removes a new accepted domain in Exchange
/// </summary>
/// <param name="domainName">DomainName to remove</param>
public void Remove_AcceptedDomain(string domainName)
{
try
{
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// INFO //
this.logger.Info("Disabling " + domainName + " as an Accepted Domain in Exchange");
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
PSCommand cmd = new PSCommand();
cmd.AddCommand("Remove-AcceptedDomain");
cmd.AddParameter("Identity", domainName);
cmd.AddParameter("DomainController", domainController);
cmd.AddParameter("Confirm", false);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// INFO //
this.logger.Info("Successfully disabled " + domainName + " as an Accepted Domain in Exchange in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception)
{
// FATAL //
this.logger.Fatal("Failed to disable " + domainName + " as an Accepted Domain in Exchange.");
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例8: Remove_DistributionGroupMember
/// <summary>
/// Removes a member from distribution group
/// </summary>
/// <param name="groupEmailAddress"></param>
/// <param name="userPrincipalName"></param>
public void Remove_DistributionGroupMember(string groupEmailAddress, string userPrincipalName)
{
try
{
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Removing member from distribution group " + groupEmailAddress + ". Member login name: " + userPrincipalName);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Update the distribution group
PSCommand cmd = new PSCommand();
cmd.AddCommand("Remove-DistributionGroupMember");
cmd.AddParameter("Identity", groupEmailAddress);
cmd.AddParameter("Member", userPrincipalName);
cmd.AddParameter("DomainController", this.domainController);
cmd.AddParameter("Confirm", false);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
}
catch (Exception)
{
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例9: Remove_DistributionGroup
/// <summary>
/// Removes a distribution group from Exchange
/// </summary>
/// <param name="emailAddress"></param>
public void Remove_DistributionGroup(string emailAddress)
{
try
{
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Deleting distribution group " + emailAddress);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
PSCommand cmd = new PSCommand();
cmd.AddCommand("Remove-DistributionGroup");
cmd.AddParameter("Identity", emailAddress);
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// DEBUG //
logger.Debug("Successfully deleted the distribution group " + emailAddress + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception ex)
{
// Do not throw error if it already exists
if (!ex.ToString().Contains("couldn't be found on"))
throw;
else
this.logger.Info("Powershell error was thrown because the distribution group does not exist in Exchange. Continuing without error.");
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例10: Set_DistributionGroup
/// <summary>
/// Updates an existing distribution group
/// </summary>
/// <param name="displayName"></param>
/// <param name="companyCode"></param>
/// <param name="oldEmailAddress"></param>
/// <param name="emailAddress"></param>
/// <param name="companyDN"></param>
/// <param name="memberJoinRestriction"></param>
/// <param name="memberDepartRestriction"></param>
/// <param name="moderationEnabled"></param>
/// <param name="sendModerationNotifications"></param>
/// <param name="moderatedBy"></param>
/// <param name="allowedSenders"></param>
/// <param name="bypassModerationSenders"></param>
/// <param name="isHidden"></param>
/// <param name="requireSenderAuthentication"></param>
public void Set_DistributionGroup(string displayName, string companyCode, string oldEmailAddress, string emailAddress, string memberJoinRestriction, string memberDepartRestriction,
bool moderationEnabled, string sendModerationNotifications, List<string> managedBy, List<string> moderatedBy, List<string> allowedSenders,
List<string> bypassModerationSenders, bool isHidden, bool requireSenderAuthentication)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Updating existing distribution group. New name: [" + displayName + "] for company code " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Update the distribution group
PSCommand cmd = new PSCommand();
cmd.AddCommand("Set-DistributionGroup");
cmd.AddParameter("Identity", oldEmailAddress);
cmd.AddParameter("DisplayName", displayName);
cmd.AddParameter("PrimarySmtpAddress", emailAddress);
cmd.AddParameter("MemberJoinRestriction", memberJoinRestriction);
cmd.AddParameter("MemberDepartRestriction", memberDepartRestriction);
cmd.AddParameter("ModerationEnabled", moderationEnabled);
cmd.AddParameter("SendModerationNotifications", sendModerationNotifications);
cmd.AddParameter("HiddenFromAddressListsEnabled", isHidden);
cmd.AddParameter("RequireSenderAuthenticationEnabled", requireSenderAuthentication);
cmd.AddParameter("ManagedBy", managedBy.ToArray());
cmd.AddParameter("DomainController", this.domainController);
// Check to see if allowed senders is set or not
if (allowedSenders != null && allowedSenders.Count > 0)
cmd.AddParameter("AcceptMessagesOnlyFromSendersOrMembers", allowedSenders.ToArray());
else
cmd.AddParameter("AcceptMessagesOnlyFromSendersOrMembers", null);
// Check if it must be approved by an administrator
if (moderationEnabled)
{
if (bypassModerationSenders != null && bypassModerationSenders.Count > 0)
cmd.AddParameter("BypassModerationFromSendersOrMembers", bypassModerationSenders.ToArray());
else
cmd.AddParameter("BypassModerationFromSendersOrMembers", null);
}
else
cmd.AddParameter("BypassModerationFromSendersOrMembers", null);
// Only add ModeratedBy if it was checked
if (moderationEnabled)
cmd.AddParameter("ModeratedBy", moderatedBy.ToArray());
else
cmd.AddParameter("ModeratedBy", null);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
}
catch (Exception)
{
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例11: Update_ActiveSyncPolicy
//.........这里部分代码省略.........
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Update the distribution group
PSCommand cmd = new PSCommand();
cmd.AddCommand("Set-ActiveSyncMailboxPolicy");
if (!string.IsNullOrEmpty(policy.OldDisplayName))
cmd.AddParameter("Identity", policy.OldDisplayName);
else
cmd.AddParameter("Identity", policy.DisplayName);
cmd.AddParameter("Name", policy.DisplayName);
cmd.AddParameter("AllowBluetooth", policy.AllowBluetooth);
cmd.AddParameter("AllowBrowser", policy.AllowBrowser);
cmd.AddParameter("AllowCamera", policy.AllowCamera);
cmd.AddParameter("AllowConsumerEmail", policy.AllowConsumerEmail);
cmd.AddParameter("AllowDesktopSync", policy.AllowDesktopSync);
cmd.AddParameter("AllowHTMLEmail", policy.AllowHTMLEmail);
cmd.AddParameter("AllowInternetSharing", policy.AllowInternetSharing);
cmd.AddParameter("AllowIrDA", policy.AllowIrDA);
cmd.AddParameter("AllowNonProvisionableDevices", policy.AllowNonProvisionableDevice);
cmd.AddParameter("AllowRemoteDesktop", policy.AllowRemoteDesktop);
cmd.AddParameter("AllowSimpleDevicePassword", policy.AllowSimpleDevicePassword);
cmd.AddParameter("AllowStorageCard", policy.AllowStorageCard);
cmd.AddParameter("AllowTextMessaging", policy.AllowTextMessaging);
cmd.AddParameter("AllowUnsignedApplications", policy.AllowUnsignedApplications);
cmd.AddParameter("AllowUnsignedInstallationPackages", policy.AllowUnsignedInstallationPackages);
cmd.AddParameter("AllowWiFi", policy.AllowWiFi);
cmd.AddParameter("AlphanumericDevicePasswordRequired", policy.AlphanumericDevicePasswordRequired);
cmd.AddParameter("AttachmentsEnabled", policy.AttachmentsEnabled);
cmd.AddParameter("DeviceEncryptionEnabled", policy.DeviceEncryptionEnabled);
cmd.AddParameter("DevicePasswordEnabled", policy.DevicePasswordEnabled);
cmd.AddParameter("MaxCalendarAgeFilter", policy.MaxCalendarAgeFilter);
cmd.AddParameter("MaxEmailAgeFilter", policy.MaxEmailAgeFilter);
cmd.AddParameter("PasswordRecoveryEnabled", policy.PasswordRecoveryEnabled);
cmd.AddParameter("RequireStorageCardEncryption", policy.RequireStorageCardEncryption);
cmd.AddParameter("RequireManualSyncWhenRoaming", policy.RequireManualSyncWhenRoaming);
if (policy.DevicePolicyRefreshInterval > 0)
cmd.AddParameter("DevicePolicyRefreshInterval", new TimeSpan(policy.DevicePolicyRefreshInterval, 0, 0).ToString());
else
cmd.AddParameter("DevicePolicyRefreshInterval", "Unlimited");
if (policy.MaxAttachmentSize > 0)
cmd.AddParameter("MaxAttachmentSize", policy.MaxAttachmentSize + "KB");
else
cmd.AddParameter("MaxAttachmentSize", "Unlimited");
if (policy.MaxDevicePasswordFailedAttempts > 0)
cmd.AddParameter("MaxDevicePasswordFailedAttempts", policy.MaxDevicePasswordFailedAttempts);
else
cmd.AddParameter("MaxDevicePasswordFailedAttempts", "Unlimited");
if (policy.MaxEmailBodyTruncationSize > 0)
cmd.AddParameter("MaxEmailBodyTruncationSize", policy.MaxEmailBodyTruncationSize);
else
cmd.AddParameter("MaxEmailBodyTruncationSize", "Unlimited");
if (policy.MaxInactivityTimeDeviceLock > 0)
cmd.AddParameter("MaxInactivityTimeDeviceLock", new TimeSpan(0, policy.MaxInactivityTimeDeviceLock, 0).ToString());
else
cmd.AddParameter("MaxInactivityTimeDeviceLock", "Unlimited");
if (policy.MinDevicePasswordComplexCharacters > 0)
cmd.AddParameter("MinDevicePasswordComplexCharacters", policy.MinDevicePasswordComplexCharacters);
else
cmd.AddParameter("MinDevicePasswordComplexCharacters", 1);
if (policy.MinDevicePasswordLength > 0)
cmd.AddParameter("MinDevicePasswordLength", policy.MinDevicePasswordLength);
else
cmd.AddParameter("MinDevicePasswordLength", null);
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", this.domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// DEBUG //
logger.Info("Updated Activesync mailbox policy " + policy.DisplayName + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception)
{
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
开发者ID:KnowMoreIT,项目名称:CloudPanel_3.0,代码行数:101,代码来源:ExchCmds+(DXN-PC's+conflicted+copy+2013-11-01).cs
示例12: New_DistributionGroup
//.........这里部分代码省略.........
/// <param name="requireSenderAuthentication"></param>
public void New_DistributionGroup(string displayName, string companyCode, string emailAddress, string companyDN, string memberJoinRestriction, string memberDepartRestriction,
bool moderationEnabled, string sendModerationNotifications, List<string> members, List<string> managedBy, List<string> moderatedBy, List<string> allowedSenders,
List<string> bypassModerationSenders, bool isHidden, bool requireSenderAuthentication)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Creating a new distribution group named [" + displayName + "] for company code " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Create SamAccountName
string samAccountName = emailAddress.Replace("@", "_");
if (samAccountName.Length > 19)
samAccountName = samAccountName.Substring(0, 18);
// Create the distribution group
PSCommand cmd = new PSCommand();
cmd.AddCommand("New-DistributionGroup");
cmd.AddParameter("Name", displayName);
cmd.AddParameter("Alias", emailAddress.Replace("@", "_"));
cmd.AddParameter("SamAccountName", samAccountName);
cmd.AddParameter("DisplayName", displayName);
cmd.AddParameter("PrimarySmtpAddress", emailAddress);
cmd.AddParameter("OrganizationalUnit", companyDN);
cmd.AddParameter("MemberJoinRestriction", memberJoinRestriction);
cmd.AddParameter("MemberDepartRestriction", memberDepartRestriction);
cmd.AddParameter("ModerationEnabled", moderationEnabled);
cmd.AddParameter("SendModerationNotifications", sendModerationNotifications);
cmd.AddParameter("Members", members.ToArray());
cmd.AddParameter("ManagedBy", managedBy.ToArray());
cmd.AddParameter("DomainController", this.domainController);
// Only add ModeratedBy if it was checked
if (moderationEnabled)
cmd.AddParameter("ModeratedBy", moderatedBy.ToArray());
else
cmd.AddParameter("ModeratedBy", null);
powershell.Commands = cmd;
powershell.Invoke();
// Set the other options for the distribution group
cmd = new PSCommand();
cmd.AddCommand("Set-DistributionGroup");
cmd.AddParameter("Identity", emailAddress.Replace("@", "_"));
cmd.AddParameter("CustomAttribute1", companyCode);
cmd.AddParameter("HiddenFromAddressListsEnabled", isHidden);
cmd.AddParameter("RequireSenderAuthenticationEnabled", requireSenderAuthentication);
cmd.AddParameter("DomainController", this.domainController);
// Check to see if allowed senders is set or not
if (allowedSenders != null && allowedSenders.Count > 0)
cmd.AddParameter("AcceptMessagesOnlyFromSendersOrMembers", allowedSenders.ToArray());
else
cmd.AddParameter("AcceptMessagesOnlyFromSendersOrMembers", null);
// Check if it must be approved by an administrator
if (moderationEnabled)
{
if (bypassModerationSenders != null && bypassModerationSenders.Count > 0)
cmd.AddParameter("BypassModerationFromSendersOrMembers", bypassModerationSenders.ToArray());
else
cmd.AddParameter("BypassModerationFromSendersOrMembers", null);
}
else
cmd.AddParameter("BypassModerationFromSendersOrMembers", null);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
}
catch (Exception ex)
{
// FATAL //
logger.Debug("Error creating a new distribution group named [" + displayName + "] for company code " + companyCode + ". Path: " + companyDN, ex);
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
开发者ID:KnowMoreIT,项目名称:CloudPanel_3.0,代码行数:101,代码来源:ExchCmds+(DXN-PC's+conflicted+copy+2013-11-01).cs
示例13: Get_Mailbox
//.........这里部分代码省略.........
public BaseMailbox Get_Mailbox(string userPrincipalName)
{
// Our return object
BaseMailbox mailbox = new BaseMailbox();
try
{
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Getting mailbox for [" + userPrincipalName + "]");
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Get the Mailbox
PSCommand cmd = new PSCommand();
cmd.AddCommand("Get-Mailbox");
cmd.AddParameter("Identity", userPrincipalName);
cmd.AddParameter("DomainController", this.domainController);
powershell.Commands = cmd;
// Invoke and get returned information
foreach (PSObject ps in powershell.Invoke())
{
// Debug information
foreach (PSMemberInfo psmi in ps.Members)
{
// DEBUG //
if (psmi.Value == null)
this.logger.Debug("Value for [" + psmi.Name + "] was null.");
else
this.logger.Debug("Value for [" + psmi.Name + "] is " + psmi.Value.ToString());
}
mailbox.DisplayName = ps.Members["DisplayName"].Value.ToString();
mailbox.PrimarySmtpAddress = ps.Members["PrimarySmtpAddress"].Value.ToString();
mailbox.HiddenFromAddressListsEnabled = bool.Parse(ps.Members["HiddenFromAddressListsEnabled"].Value.ToString());
mailbox.DeliverToMailboxAndForward = bool.Parse(ps.Members["DeliverToMailboxAndForward"].Value.ToString());
if (ps.Members["ForwardingAddress"] != null)
{
mailbox.ForwardingAddress = ps.Members["ForwardingAddress"].Value.ToString();
}
// Format the quota
string quota = ps.Members["ProhibitSendReceiveQuota"].Value.ToString();
// Strip data because Exchange resturns something like this: 4.25GB (111,111,1111 bytes).
// We need the bytes
int first = quota.IndexOf("(");
int last = quota.IndexOf(")");
quota = quota.Substring(first, last - first);
// Remove characters
quota = quota.Replace("bytes", string.Empty);
quota = quota.Replace(",", string.Empty);
quota = quota.Replace(" ", string.Empty);
quota = quota.Replace(")", string.Empty);
quota = quota.Replace("(", string.Empty);
// Log the quota
this.logger.Debug("Formatted quota is now: " + quota + " for user " + mailbox.DisplayName);
// Convert from bytes to MB
decimal mb = decimal.Parse(quota);
mb = ((mb / 1024) / 1024);
mailbox.ProhibitSendReceiveQuota = decimal.Round(mb, 2, MidpointRounding.AwayFromZero);
// Get email addresses
mailbox.EmailAddresses = ps.Members["EmailAddresses"].Value.ToString().Split(' ');
}
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// DEBUG //
logger.Debug("Successfully retrieved mailbox information for [" + userPrincipalName + "] in " + stopwatch.Elapsed.ToString() + " second(s)");
// Return mailbox data
return mailbox;
}
catch (Exception ex)
{
// DEBUG //
this.logger.Error("Error getting mailbox information for " + userPrincipalName + ": " + ex.ToString());
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
开发者ID:KnowMoreIT,项目名称:CloudPanel_3.0,代码行数:101,代码来源:ExchCmds+(DXN-PC's+conflicted+copy+2013-11-01).cs
示例14: Set_CASMailbox
/// <summary>
/// Sets more details on the CAS mailbox
/// </summary>
/// <param name="userPrincipalName"></param>
/// <param name="companyCode"></param>
/// <param name="activeSyncEnabled"></param>
/// <param name="ecpEnabled"></param>
/// <param name="imapEnabled"></param>
/// <param name="mapiEnabled"></param>
/// <param name="owaEnabled"></param>
/// <param name="POPEnabled"></param>
public void Set_CASMailbox(string userPrincipalName, string companyCode, bool activeSyncEnabled, bool ecpEnabled, bool imapEnabled, bool mapiEnabled, bool owaEnabled, bool POPEnabled, string activeSyncPolicyName = null)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// DEBUG //
logger.Debug("Setting details on CAS mailbox for user [" + userPrincipalName + "] for company code " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
// Enable the mailbox
PSCommand cmd = new PSCommand();
cmd.AddCommand("Set-CASMailbox");
cmd.AddParameter("Identity", userPrincipalName);
cmd.AddParameter("ActiveSyncEnabled", activeSyncEnabled);
cmd.AddParameter("ECPEnabled", ecpEnabled);
cmd.AddParameter("ImapEnabled", imapEnabled);
cmd.AddParameter("MAPIEnabled", mapiEnabled);
cmd.AddParameter("OWAEnabled", owaEnabled);
cmd.AddParameter("PopEnabled", POPEnabled);
if (!string.IsNullOrEmpty(activeSyncPolicyName))
cmd.AddParameter("ActiveSyncMailboxPolicy", activeSyncPolicyName);
else
cmd.AddParameter("ActiveSyncMailboxPolicy", null);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// DEBUG //
logger.Debug("Successfully set details on CAS mailbox for [" + userPrincipalName + "] for company code " + companyCode + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception)
{
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}
示例15: Remove_PublicFolderDefaultPermissions
/// <summary>
/// Removes the default public folder permissions for a company's public folder
/// </summary>
/// <param name="companyCode"></param>
/// <param name="exchangeVersion"></param>
public void Remove_PublicFolderDefaultPermissions(string companyCode, int exchangeVersion)
{
try
{
// Strip whitespace from company code
companyCode = companyCode.Replace(" ", string.Empty);
// Start clock
Stopwatch stopwatch = Stopwatch.StartNew();
// INFO //
this.logger.Info("Removing default public folder permissions for " + companyCode);
// Run commands
powershell = PowerShell.Create();
powershell.Runspace = runspace;
PSCommand cmd = new PSCommand();
if (exchangeVersion == 2010)
{
// Remove Default permissions
cmd.AddCommand("Remove-PublicFolderClientPermission");
cmd.AddParameter("Identity", @"\" + companyCode);
cmd.AddParameter("User", "Default");
cmd.AddParameter("AccessRights", "Author");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Remove Anonymous permissions
cmd = new PSCommand();
cmd.AddCommand("Remove-PublicFolderClientPermission");
cmd.AddParameter("Identity", @"\" + companyCode);
cmd.AddParameter("User", "Anonymous");
cmd.AddParameter("AccessRights", "CreateItems");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
}
else if (exchangeVersion == 2013)
{
// Remove Default permissions
cmd.AddCommand("Remove-PublicFolderClientPermission");
cmd.AddParameter("Identity", @"\" + companyCode);
cmd.AddParameter("User", "Default");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
// Remove Anonymous permissions
cmd = new PSCommand();
cmd.AddCommand("Remove-PublicFolderClientPermission");
cmd.AddParameter("Identity", @"\" + companyCode);
cmd.AddParameter("User", "Anonymous");
cmd.AddParameter("Confirm", false);
cmd.AddParameter("DomainController", domainController);
powershell.Commands = cmd;
powershell.Invoke();
}
// Stop the clock
stopwatch.Stop();
// Check for errors
CheckErrors(ref powershell);
// INFO //
this.logger.Info("Successfully removed permissions for public folder " + companyCode + " in " + stopwatch.Elapsed.ToString() + " second(s)");
}
catch (Exception ex)
{
// FATAL //
this.logger.Fatal("Failed to create public folder for " + companyCode, ex);
throw;
}
finally
{
if (powershell != null)
powershell.Dispose();
}
}