private void DeleteDomainInternal(string domainName) { HostedSolutionLog.LogStart("DeleteDomainInternal"); HostedSolutionLog.DebugInfo("Domain Name: {0}", domainName); try { if (string.IsNullOrEmpty(domainName)) { throw new ArgumentException("domainName"); } using (ManagementObject domainObj = GetDomain(domainName)) { if (domainObj == null) { HostedSolutionLog.LogWarning("OCS internal domain '{0}' not found", domainName); } else { domainObj.Delete(); } } } catch (Exception ex) { HostedSolutionLog.LogError("DeleteDomainInternal", ex); throw; } HostedSolutionLog.LogEnd("DeleteDomainInternal"); }
public override void SetPeoplePickerOu(string site, string ou) { HostedSolutionLog.LogStart("SetPeoplePickerOu"); HostedSolutionLog.LogInfo(" Site: {0}", site); HostedSolutionLog.LogInfo(" OU: {0}", ou); Runspace runSpace = null; try { List <SharePointSiteCollection> siteCollections = new List <SharePointSiteCollection>(); runSpace = OpenRunspace(); Command cmd = new Command("Set-SPSite"); cmd.Parameters.Add("Identity", site); cmd.Parameters.Add("UserAccountDirectoryPath", ou); ExecuteShellCommand(runSpace, cmd); } finally { CloseRunspace(runSpace); } HostedSolutionLog.LogEnd("SetPeoplePickerOu"); }
/// <summary>Executes shell command.</summary> /// <param name="runspace">The runspace.</param> /// <param name="scripts">The scripts to be executed.</param> /// <param name="errors">The errors.</param> /// <returns>PSobjecs collection.</returns> private Collection <PSObject> ExecuteShellCommand(Runspace runspace, List <string> scripts, out object[] errors) { HostedSolutionLog.LogStart("ExecuteShellCommand"); var errorList = new List <object>(); Collection <PSObject> results; using (Pipeline pipeLine = runspace.CreatePipeline()) { foreach (string script in scripts) { pipeLine.Commands.AddScript(script); } results = pipeLine.Invoke(); if (pipeLine.Error != null && pipeLine.Error.Count > 0) { foreach (object item in pipeLine.Error.ReadToEnd()) { errorList.Add(item); string errorMessage = string.Format("Invoke error: {0}", item); HostedSolutionLog.LogWarning(errorMessage); throw new ArgumentException(scripts.First()); } } } errors = errorList.ToArray(); HostedSolutionLog.LogEnd("ExecuteShellCommand"); return(results); }
/// <summary> /// Checks the object from the shell execution result. /// </summary> /// <param name="result"></param> /// <returns>Distinguished name of the object if object exists or null otherwise.</returns> internal string CheckResultObjectDN(Collection <PSObject> result) { HostedSolutionLog.LogStart("CheckResultObjectDN"); if (result == null) { return(null); } if (result.Count < 1) { return(null); } PSMemberInfo info = result[0].Members["DistinguishedName"]; if (info == null) { throw new ArgumentException("Execution result does not contain DistinguishedName property", "result"); } string ret = info.Value.ToString(); HostedSolutionLog.LogEnd("CheckResultObjectDN"); return(ret); }
/// <summary> /// Returns the identity of the object from the shell execution result /// </summary> /// <param name="result"></param> /// <returns></returns> internal string GetResultObjectIdentity(Collection <PSObject> result) { HostedSolutionLog.LogStart("GetResultObjectIdentity"); if (result == null) { throw new ArgumentNullException("result", "Execution result is not specified"); } if (result.Count < 1) { throw new ArgumentException("Execution result is empty", "result"); } if (result.Count > 1) { throw new ArgumentException("Execution result contains more than one object", "result"); } PSMemberInfo info = result[0].Members["Identity"]; if (info == null) { throw new ArgumentException("Execution result does not contain Identity property", "result"); } string ret = info.Value.ToString(); HostedSolutionLog.LogEnd("GetResultObjectIdentity"); return(ret); }
internal void DeleteUserInternal(string loginName, string organizationId) { HostedSolutionLog.LogStart("DeleteUserInternal"); HostedSolutionLog.DebugInfo("loginName : {0}", loginName); HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId); if (string.IsNullOrEmpty(loginName)) { throw new ArgumentNullException("loginName"); } if (string.IsNullOrEmpty(organizationId)) { throw new ArgumentNullException("organizationId"); } string path = GetUserPath(organizationId, loginName); if (ActiveDirectoryUtils.AdObjectExists(path)) { ActiveDirectoryUtils.DeleteADObject(path); } HostedSolutionLog.LogEnd("DeleteUserInternal"); }
private void AddDomainInternal(string domainName) { HostedSolutionLog.LogStart("AddDomainInternal"); HostedSolutionLog.DebugInfo("Domain Name: {0}", domainName); try { if (string.IsNullOrEmpty(domainName)) { throw new ArgumentException("domainName"); } if (GetDomain(domainName) != null) { HostedSolutionLog.LogWarning("OCS internal domain '{0}' already exists", domainName); } else { using (ManagementObject newDomain = Wmi.CreateInstance("MSFT_SIPFederationInternalDomainData")) { newDomain["SupportedInternalDomain"] = domainName; newDomain.Put(); } } } catch (Exception ex) { HostedSolutionLog.LogError("AddDomainInternal", ex); throw; } HostedSolutionLog.LogEnd("AddDomainInternal"); }
private void SetUserGeneralSettingsInternal(string instanceId, bool enabledForFederation, bool enabledForPublicIMConectivity, bool archiveInternalCommunications, bool archiveFederatedCommunications, bool enabledForEnhancedPresence) { HostedSolutionLog.LogStart("SetUserGeneralSettingsInternal"); try { if (string.IsNullOrEmpty(instanceId)) { throw new ArgumentException("instanceId"); } using (ManagementObject userObject = GetUserByInstanceId(instanceId)) { if (userObject == null) { throw new Exception(string.Format("OCS user {0} not found", instanceId)); } userObject["EnabledForFederation"] = enabledForFederation; userObject["PublicNetworkEnabled"] = enabledForPublicIMConectivity; userObject["ArchiveInternalCommunications"] = archiveInternalCommunications; userObject["ArchiveFederatedCommunications"] = archiveFederatedCommunications; if (enabledForEnhancedPresence) { userObject["EnabledForEnhancedPresence"] = true; } userObject.Put(); } } catch (Exception ex) { HostedSolutionLog.LogError("SetUserGeneralSettingsInternal", ex); throw; } HostedSolutionLog.LogEnd("SetUserGeneralSettingsInternal"); }
private void SetUserPrimaryUriInternal(string instanceId, string userUpn) { HostedSolutionLog.LogStart("SetUserPrimaryUriInternal"); try { if (string.IsNullOrEmpty(instanceId)) { throw new ArgumentException("instanceId"); } if (string.IsNullOrEmpty(userUpn)) { throw new ArgumentException("userUpn"); } using (ManagementObject userObject = GetUserByInstanceId(instanceId)) { if (userObject == null) { throw new Exception(string.Format("OCS user {0} not found", instanceId)); } string primaryUri = "sip:" + userUpn; userObject["PrimaryURI"] = primaryUri; userObject.Put(); } } catch (Exception ex) { HostedSolutionLog.LogError("SetUserPrimaryUriInternal", ex); throw; } HostedSolutionLog.LogEnd("SetUserPrimaryUriInternal"); }
/// <summary> Gets allowed domains.</summary> /// <param name="organizationId"> The organization identifier.</param> /// <returns> Allowed domains.</returns> internal override LyncFederationDomain[] GetFederationDomainsInternal(string organizationId) { HostedSolutionLog.LogStart("GetFederationDomainsInternal"); HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); LyncFederationDomain[] domains; Runspace runspace = null; try { runspace = OpenRunspace(); domains = GetFederationDomainsInternal(runspace); } catch (Exception ex) { HostedSolutionLog.LogError("GetFederationDomainsInternal", ex); throw; } finally { CloseRunspace(runspace); } HostedSolutionLog.LogEnd("GetFederationDomainsInternal"); return(domains); }
/// <summary> Deletes user.</summary> /// <param name="userUpn"> The user UPN.</param> /// <returns> The result.</returns> internal override bool DeleteUserInternal(string userUpn) { HostedSolutionLog.LogStart("DeleteUserInternal"); HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn); Runspace runspace = null; try { runspace = OpenRunspace(); DeleteUser(runspace, userUpn); var command = new Command("Get-CsAdUser"); command.Parameters.Add("Identity", userUpn); ExecuteShellCommand(runspace, command, false); command = new Command("Update-CsAddressBook"); ExecuteShellCommand(runspace, command, false); command = new Command("Update-CsUserDatabase"); ExecuteShellCommand(runspace, command, false); } catch (Exception ex) { HostedSolutionLog.LogError("DeleteUserInternal", ex); throw; } finally { CloseRunspace(runspace); } HostedSolutionLog.LogEnd("DeleteUserInternal"); return(true); }
/// <summary> Removes domain from allowed list.</summary> /// <param name="organizationId"> The organization identifier.</param> /// <param name="domainName"> The domain name.</param> /// <returns> The result.</returns> internal override bool RemoveFederationDomainInternal(string organizationId, string domainName) { HostedSolutionLog.LogStart("RemoveFederationDomainInternal"); HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); HostedSolutionLog.DebugInfo("domainName: {0}", domainName); Runspace runspace = null; try { runspace = OpenRunspace(); var command = new Command("Remove-CsAllowedDomain"); command.Parameters.Add("Identity", domainName); ExecuteShellCommand(runspace, command, false); } catch (Exception ex) { HostedSolutionLog.LogError("RemoveFederationDomainInternal", ex); throw; } finally { CloseRunspace(runspace); } HostedSolutionLog.LogEnd("RemoveFederationDomainInternal"); return(true); }
/// <summary> Rollbacks the transaction.</summary> /// <param name="transaction"> The transaction.</param> internal void RollbackTransaction(LyncTransaction transaction) { HostedSolutionLog.LogStart("RollbackTransaction"); Runspace runspace = null; try { runspace = OpenRunspace(); for (int i = transaction.Actions.Count - 1; i > -1; i--) { try { RollbackAction(transaction.Actions[i], runspace); } catch (Exception ex) { HostedSolutionLog.LogError("Rollback error", ex); } } } catch (Exception ex) { HostedSolutionLog.LogError("Rollback error", ex); } finally { CloseRunspace(runspace); } HostedSolutionLog.LogEnd("RollbackTransaction"); }
/// <summary>Opens PowerShell runspace.</summary> /// <returns>The runspace.</returns> private Runspace OpenRunspace() { HostedSolutionLog.LogStart("OpenRunspace"); if (runspaceConfiguration == null) { runspaceConfiguration = RunspaceConfiguration.Create(); PSSnapInException exception; runspaceConfiguration.AddPSSnapIn(SharepointSnapInName, out exception); HostedSolutionLog.LogInfo("Sharepoint snapin loaded"); if (exception != null) { HostedSolutionLog.LogWarning("SnapIn error", exception); } } Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); runspace.SessionStateProxy.SetVariable("ConfirmPreference", "none"); HostedSolutionLog.LogEnd("OpenRunspace"); return(runspace); }
private void DeleteUserInternal(string instanceId) { HostedSolutionLog.LogStart("DeleteUserInternal"); try { if (string.IsNullOrEmpty(instanceId)) { throw new ArgumentException("instanceId"); } using (ManagementObject userObject = GetUserByInstanceId(instanceId)) { if (userObject == null) { HostedSolutionLog.LogWarning("OCS user {0} not found", instanceId); } else { userObject.Delete(); } } } catch (Exception ex) { HostedSolutionLog.LogError("DeleteUserInternal", ex); throw; } HostedSolutionLog.LogEnd("DeleteUserInternal"); }
private ManagementObject GetUserByInstanceId(string instanceId) { HostedSolutionLog.LogStart("GetUserByInstanceId"); ManagementObject objUser = Wmi.GetWmiObject("MSFT_SIPESUserSetting", "InstanceID = '{0}'", instanceId); HostedSolutionLog.LogEnd("GetUserByInstanceId"); return(objUser); }
private ManagementObject GetDomain(string domainName) { HostedSolutionLog.LogStart("GetDomain"); ManagementObject objDomain = Wmi.GetWmiObject("MSFT_SIPFederationInternalDomainData", "SupportedInternalDomain='{0}'", domainName); HostedSolutionLog.LogEnd("GetDomain"); return(objDomain); }
/// <summary> /// Creates organization domain /// </summary> /// <param name="organizationDistinguishedName"></param> /// <param name="domain"></param> private void CreateOrganizationDomainInternal(string organizationDistinguishedName, string domain) { HostedSolutionLog.LogStart("CreateOrganizationDomainInternal"); string path = ActiveDirectoryUtils.AddADPrefix(organizationDistinguishedName, PrimaryDomainController); ActiveDirectoryUtils.AddUPNSuffix(path, domain); HostedSolutionLog.LogEnd("CreateOrganizationDomainInternal"); }
/// <summary>Restores site collection under given url from backup.</summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="siteCollection">Site collection to be restored.</param> /// <param name="filename">Backup file name to restore from.</param> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> public void RestoreSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection, string filename) { string url = siteCollection.Url; try { string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port); HostedSolutionLog.LogStart("RestoreSiteCollection"); HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl); HostedSolutionLog.DebugInfo("backupFilePath: {0}", filename); Runspace runspace = null; try { string tempPath = Path.GetTempPath(); string expandedFile = filename; if (Path.GetExtension(filename).ToLower() == ".zip") { expandedFile = FileUtils.UnzipFiles(filename, tempPath)[0]; // Delete zip archive. FileUtils.DeleteFile(filename); } runspace = OpenRunspace(); DeleteSiteCollection(runspace, siteCollectionUrl, false); var command = new Command("Restore-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); command.Parameters.Add("Path", filename); ExecuteShellCommand(runspace, command); command = new Command("Set-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); command.Parameters.Add("OwnerAlias", siteCollection.OwnerLogin); ExecuteShellCommand(runspace, command); command = new Command("Set-SPUser"); command.Parameters.Add("Identity", siteCollection.OwnerLogin); command.Parameters.Add("Email", siteCollection.OwnerEmail); command.Parameters.Add("DisplayName", siteCollection.Name); ExecuteShellCommand(runspace, command); FileUtils.DeleteFile(expandedFile); } finally { CloseRunspace(runspace); HostedSolutionLog.LogEnd("RestoreSiteCollection"); } } catch (Exception ex) { throw new InvalidOperationException("Failed to restore site collection.", ex); } }
/// <summary> Deletes sip domain.</summary> /// <param name="runspace"> The runspace.</param> /// <param name="id"> The identifier.</param> internal void DeleteSipDomain(Runspace runspace, string id) { HostedSolutionLog.LogStart("DeleteSipDomain"); HostedSolutionLog.DebugInfo("SipDomain : {0}", id); var command = new Command("Remove-CsSipDomain"); command.Parameters.Add("Identity", id); command.Parameters.Add("Confirm", false); command.Parameters.Add("Force", true); ExecuteShellCommand(runspace, command, false); HostedSolutionLog.LogEnd("DeleteSipDomain"); }
/// <summary> Deletes user.</summary> /// <param name="runspace"> The runspace.</param> /// <param name="userUpn"> The user UPN.</param> internal void DeleteUser(Runspace runspace, string userUpn) { HostedSolutionLog.LogStart("DeleteUser"); HostedSolutionLog.DebugInfo("userUpn : {0}", userUpn); var command = new Command("Disable-CsUser"); command.Parameters.Add("Identity", userUpn); command.Parameters.Add("Confirm", false); ExecuteShellCommand(runspace, command, false); HostedSolutionLog.LogEnd("DeleteUser"); }
/// <summary> Deletes mobility policy.</summary> /// <param name="runspace"> The runspace.</param> /// <param name="policyName"> The policy name.</param> internal void DeleteMobilityPolicy(Runspace runspace, string policyName) { HostedSolutionLog.LogStart("DeleteMobilityPolicy"); HostedSolutionLog.DebugInfo("policyName : {0}", policyName); var command = new Command("Remove-CsMobilityPolicy"); command.Parameters.Add("Identity", policyName); command.Parameters.Add("Confirm", false); command.Parameters.Add("Force", true); ExecuteShellCommand(runspace, command, false); HostedSolutionLog.LogEnd("DeleteMobilityPolicy"); }
/// <summary> Backups site collection under give url.</summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="url">Url that uniquely identifies site collection to be deleted.</param> /// <param name="filename">Resulting backup file name.</param> /// <param name="zip">A value which shows whether created backup must be archived.</param> /// <param name="tempPath">Custom temp path for backup</param> /// <returns>Full path to created backup.</returns> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> public string BackupSiteCollection(Uri rootWebApplicationUri, string url, string filename, bool zip, string tempPath) { try { string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port); HostedSolutionLog.LogStart("BackupSiteCollection"); HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl); if (String.IsNullOrEmpty(tempPath)) { tempPath = Path.GetTempPath(); } string backupFileName = Path.Combine(tempPath, (zip ? StringUtils.CleanIdentifier(siteCollectionUrl) + ".bsh" : StringUtils.CleanIdentifier(filename))); HostedSolutionLog.DebugInfo("backupFilePath: {0}", backupFileName); Runspace runspace = null; try { runspace = OpenRunspace(); var command = new Command("Backup-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); command.Parameters.Add("Path", backupFileName); ExecuteShellCommand(runspace, command); if (zip) { string zipFile = Path.Combine(tempPath, filename); string zipRoot = Path.GetDirectoryName(backupFileName); FileUtils.ZipFiles(zipFile, zipRoot, new[] { Path.GetFileName(backupFileName) }); FileUtils.DeleteFile(backupFileName); backupFileName = zipFile; } return(backupFileName); } finally { CloseRunspace(runspace); HostedSolutionLog.LogEnd("BackupSiteCollection"); } } catch (Exception ex) { throw new InvalidOperationException("Failed to backup site collection.", ex); } }
private string FindUserByPrimaryUri(string uri) { string ret = null; HostedSolutionLog.LogStart("FindUserByPrimaryUri"); using (ManagementObject objUser = Wmi.GetWmiObject("MSFT_SIPESUserSetting", "PrimaryURI = '{0}'", uri)) { if (objUser != null) { ret = (string)objUser["InstanceID"]; } } HostedSolutionLog.LogEnd("FindUserByPrimaryUri"); return(ret); }
private string GetPoolDistinguishedName(string poolFQDN) { HostedSolutionLog.LogStart("GetPoolDistinguishedName"); string ret = null; using (ManagementObject objPool = Wmi.GetWmiObject("MSFT_SIPPoolSetting", "PoolFQDN = '{0}'", poolFQDN)) { if (objPool != null) { ret = (string)objPool["PoolDN"]; } } HostedSolutionLog.LogEnd("GetPoolDistinguishedName"); return(ret); }
private string FindUserByDistinguishedName(string userDistinguishedName) { string ret = null; HostedSolutionLog.LogStart("FindUserByDistinguishedName"); using (ManagementObject objUser = Wmi.GetWmiObject("MSFT_SIPESUserSetting", "UserDN = '{0}'", userDistinguishedName)) { if (objUser != null) { ret = (string)objUser["InstanceID"]; } } HostedSolutionLog.LogEnd("FindUserByDistinguishedName"); return(ret); }
/// <summary> Gets organization distinguished name.</summary> /// <param name="organizationId"> The organization identifier.</param> /// <param name="runspace"> The runspace.</param> /// <returns> The distinguished name.</returns> private string GetResultObjectDN(string organizationId, Runspace runspace) { HostedSolutionLog.LogStart("GetResultObjectDN"); string path = GetOrganizationPath(organizationId); var scripts = new List <string> { string.Format("Get-ADOrganizationalUnit -Identity \"{0}\"", path) }; Collection <PSObject> result = ExecuteShellCommand(runspace, scripts); if (result != null && result.Any()) { return(result.First().Properties["DistinguishedName"].Value.ToString()); } throw new ArgumentException("Execution result does not contain DistinguishedName property"); }
internal OrganizationUser GetUserGeneralSettingsInternal(string loginName, string organizationId) { HostedSolutionLog.LogStart("GetUserGeneralSettingsInternal"); HostedSolutionLog.DebugInfo("loginName : {0}", loginName); HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId); if (string.IsNullOrEmpty(loginName)) { throw new ArgumentNullException("loginName"); } string path = GetUserPath(organizationId, loginName); DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path); OrganizationUser retUser = new OrganizationUser(); retUser.FirstName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.FirstName); retUser.LastName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.LastName); retUser.DisplayName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DisplayName); retUser.Initials = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Initials); retUser.JobTitle = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.JobTitle); retUser.Company = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Company); retUser.Department = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Department); retUser.Office = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Office); retUser.BusinessPhone = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.BusinessPhone); retUser.Fax = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Fax); retUser.HomePhone = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.HomePhone); retUser.MobilePhone = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.MobilePhone); retUser.Pager = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Pager); retUser.WebPage = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.WebPage); retUser.Address = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Address); retUser.City = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.City); retUser.State = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.State); retUser.Zip = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Zip); retUser.Country = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Country); retUser.Notes = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Notes); retUser.ExternalEmail = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.ExternalEmail); retUser.Disabled = (bool)entry.InvokeGet(ADAttributes.AccountDisabled); retUser.Manager = GetManager(entry); retUser.DomainUserName = GetDomainName(loginName); retUser.DistinguishedName = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.DistinguishedName); retUser.Locked = (bool)entry.InvokeGet(ADAttributes.AccountLocked); HostedSolutionLog.LogEnd("GetUserGeneralSettingsInternal"); return(retUser); }
/// <summary> Opens runspace.</summary> /// <returns> The runspace.</returns> internal Runspace OpenRunspace() { HostedSolutionLog.LogStart("OpenRunspace"); if (session == null) { session = InitialSessionState.CreateDefault(); session.ImportPSModule(new[] { "ActiveDirectory", "Lync" }); } Runspace runspace = RunspaceFactory.CreateRunspace(session); runspace.Open(); runspace.SessionStateProxy.SetVariable("ConfirmPreference", "none"); HostedSolutionLog.LogEnd("OpenRunspace"); return(runspace); }
internal PasswordPolicyResult GetPasswordPolicyInternal() { HostedSolutionLog.LogStart("GetPasswordPolicyInternal"); PasswordPolicyResult res = new PasswordPolicyResult { IsSuccess = true }; string[] policyAttributes = new[] { "minPwdLength", "pwdProperties", "objectClass" }; try { DirectoryEntry domainRoot = new DirectoryEntry(ActiveDirectoryUtils.ConvertDomainName(RootDomain)); DirectorySearcher ds = new DirectorySearcher( domainRoot, "(objectClass=domainDNS)", policyAttributes, SearchScope.Base ); SearchResult result = ds.FindOne(); PasswordPolicy ret = new PasswordPolicy { MinLength = ((int)result.Properties["minPwdLength"][0]), IsComplexityEnable = ((int)result.Properties["pwdProperties"][0] == 1) }; res.Value = ret; } catch (Exception ex) { HostedSolutionLog.LogError(ex); res.IsSuccess = false; res.ErrorCodes.Add(ErrorCodes.CANNOT_GET_PASSWORD_COMPLEXITY); } HostedSolutionLog.LogEnd("GetPasswordPolicyInternal"); return(res); }