/// <summary> Creates the user.</summary> /// <param name="organizationId"> The organization identifier.</param> /// <param name="userUpn"> The user UPN.</param> /// <param name="plan"> The Lync user plan.</param> /// <returns> The result.</returns> internal override bool CreateUserInternal(string organizationId, string userUpn, LyncUserPlan plan) { HostedSolutionLog.LogStart("CreateUserInternal"); HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId); HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn); LyncTransaction transaction = StartTransaction(); Runspace runspace = null; try { runspace = OpenRunspace(); Guid guid = GetObjectGuid(organizationId, runspace); string[] tmp = userUpn.Split('@'); if (tmp.Length < 2) { return(false); } var command = new Command("Get-CsSipDomain"); Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false); bool bSipDomainExists = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower()); string path = string.Empty; if (!bSipDomainExists) { command = new Command("New-CsSipDomain"); command.Parameters.Add("Identity", tmp[1].ToLower()); ExecuteShellCommand(runspace, command, false); transaction.RegisterNewSipDomain(tmp[1].ToLower()); AddAdDomainName(organizationId, tmp[1].ToLower()); CreateSimpleUrl(runspace, guid); transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), guid.ToString()); } command = new Command("Enable-CsUser"); command.Parameters.Add("Identity", userUpn); command.Parameters.Add("RegistrarPool", PoolFQDN); command.Parameters.Add("SipAddressType", "UserPrincipalName"); ExecuteShellCommand(runspace, command, false); transaction.RegisterNewCsUser(userUpn); command = new Command("Get-CsAdUser"); command.Parameters.Add("Identity", userUpn); Collection <PSObject> result = ExecuteShellCommand(runspace, command, false); //set groupingID path = AddADPrefix(GetResultObjectDN(result)); DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path); ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-GroupingID", guid); user.CommitChanges(); command = new Command("Update-CsAddressBook"); ExecuteShellCommand(runspace, command, false); command = new Command("Update-CsUserDatabase"); ExecuteShellCommand(runspace, command, false); int trySleep = 2000; int tryMaxCount = 10; bool PlanSet = false; for (int tryCount = 0; (tryCount < tryMaxCount) && (!PlanSet); tryCount++) { try { PlanSet = SetLyncUserPlanInternal(organizationId, userUpn, plan, runspace); } catch { } if (!PlanSet) { System.Threading.Thread.Sleep(trySleep); } } } catch (Exception ex) { HostedSolutionLog.LogError("CreateUserInternal", ex); RollbackTransaction(transaction); throw; } finally { CloseRunspace(runspace); } HostedSolutionLog.LogEnd("CreateUserInternal"); return(true); }