Esempio n. 1
0
        public bool IsMailBoxAlreadyExist(string pUserCommonName, Runspace pRunspace, PowerShell pPowerShell, PSCommand pPSCommand)
        {
            pPSCommand.AddCommand("Get-Mailbox");
            pPSCommand.AddParameter("Identity", pUserCommonName);

            pPowerShell.Commands = pPSCommand;

            try
            {
                pRunspace.Open();
                pPowerShell.Runspace = pRunspace;
                Collection <PSObject> user = pPowerShell.Invoke();

                if (user == null || user.Count == 0)
                {
                    return(false);
                }

                PowerShellOperations.CheckError(pPowerShell);

                PSMemberInfo item = user[0].Properties.SingleOrDefault(property => property.Name == "RecipientType");

                if (item != null)
                {
                    if (string.Equals(item.Value.ToString(), "UserMailbox", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            finally
            {
                pRunspace.Dispose();
                pRunspace = null;
            }
            return(false);
        }
        public void CreateNewUserOnSkype(string pUserCommonName, ref ActiveDirectoryServices.ProcessInfo pProcessInfo)
        {
            Runspace   runspace;
            PowerShell powershell;
            PSCommand  command;
            var        uri = (new Uri(SkypeConnectionUri, UriKind.Absolute));

            EngineContext.Current.Resolve <IPowerShellOperations>().GetPSObjects(uri, string.Empty, out runspace, out powershell, out command);

            if (IsSkypeAccountAlreadyExist(pUserCommonName, runspace, powershell, command))
            {
                pProcessInfo = ActiveDirectoryServices.ProcessInfo.UserAlreadyExistOnSkype;
                return;
            }

            command.AddCommand("Enable-CsUser");
            command.AddParameter("Identity", pUserCommonName);
            command.AddParameter("RegistrarPool", SkypeRegistryPool);
            command.AddParameter("SipAddressType", "UserPrincipalName");

            powershell.Commands = command;

            try
            {
                runspace.Open();
                powershell.Runspace = runspace;
                powershell.Invoke();
                PowerShellOperations.CheckError(powershell);
            }
            finally
            {
                runspace.Dispose();
                runspace = null;
                powershell.Dispose();
                powershell = null;
            }
        }
Esempio n. 3
0
        public void CreateNewUserOnMailBox(string pUserCommonName, string pUserLogonName, ref ProcessInfo pProcessInfo)
        {
            Runspace   runspace;
            PowerShell powershell;
            PSCommand  command;
            var        uri = (new Uri(LiveIdConnectionUri, UriKind.Absolute));

            EngineContext.Current.Resolve <IPowerShellOperations>().GetPSObjects(uri, ShellUri, out runspace, out powershell, out command);

            if (IsMailBoxAlreadyExist(pUserCommonName, runspace, powershell, command))
            {
                pProcessInfo = ProcessInfo.UserAlreadyExistOnMailBox;
                return;
            }

            command.AddCommand("Enable-Mailbox");
            command.AddParameter("Identity", pUserCommonName);
            command.AddParameter("Alias", pUserLogonName);
            command.AddParameter("Database", GetExchangeServerDbName(pUserLogonName));

            powershell.Commands = command;

            try
            {
                runspace.Open();
                powershell.Runspace = runspace;
                powershell.Invoke();
                PowerShellOperations.CheckError(powershell);
            }
            finally
            {
                runspace.Dispose();
                runspace = null;
                powershell.Dispose();
                powershell = null;
            }
        }