0

我希望 Enable-CsUser 从我的服务器中获取 c#,该服务器在我的测试实验室中加入了我的域

lync 服务器的 FQDN 是 lync.mohsen.com,我想在我的 lync 服务器中启用“asadi”(“asadi”存在于 ldap 和 exchange 中”)

这是我的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Remoting;
using System.Management.Automation.Runspaces;
using System.Security;

namespace ConsoleApplication2
{
    class Program
    {
        static SecureString GetSecurePassword(string password)
        {
            var securePassword = new SecureString();
            foreach (var c in password)
            {
                 securePassword.AppendChar(c);
            }

            return securePassword;
        }
        static void Main(string[] args)
        {

            string lyncUser = "administrator";
            string _pass = "abc@123";
            var lyncPW = GetSecurePassword(_pass);
            var fqdnlync = "lync.mohsen.com";
            var user = "asadi";
            var sipadd = "asadi@mohsen.com";
            // lync server 2013
            //this code is same as EXchange code in schima
            PSCredential creds = new PSCredential(lyncUser, lyncPW);

            WSManConnectionInfo conn = new WSManConnectionInfo(new Uri("https://lync.mohsen.com/ocspowershell"), "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", creds);

            conn.AuthenticationMechanism = AuthenticationMechanism.Default;

            Runspace runspace_2 = RunspaceFactory.CreateRunspace(conn);
            PowerShell powershell_2 = PowerShell.Create();

            PSCommand command_2 = new PSCommand();
            command_2.AddCommand("Enable-CsUser");
            command_2.AddParameter("Identity", user);
            command_2.AddParameter("RegistrarPool", fqdnlync);
            command_2.AddParameter("SipAddressType", sipadd);
            powershell_2.Commands = command_2;

            try
            {
                runspace_2.Open();
                powershell_2.Runspace = runspace_2;
                powershell_2.Invoke();
            }
            catch (Exception ex)
            {
                //string er = ex.InnerException.ToString();
            }
            finally
            {
                runspace_2.Dispose();
                runspace_2 = null;

                powershell_2.Dispose();
                powershell_2 = null;

            }
        }
    }
}

但是这段代码不起作用!

我哪里做错了?

4

1 回答 1

0

我自己解决了这个问题

  1. 确保在 IIS / internal(在我的情况下)/ocspowershell/ authentication /windows authentication 设置为启用的 lync 服务器

  2. 改变 var sipadd = "asadi@mohsen.com" -------> var sipadd = "sip:asadi@mohsen.com"

    3.改变

    command_2.AddParameter("SipAddressType", sipadd); ----------> command_2.AddParameter("SipAddress", sipadd);

好的,谢谢

于 2014-07-24T15:44:14.207 回答