0

テスト ラボのドメインに参加しているサーバーから Enable-CsUser が c# を取得したい

Lync サーバーの FQDN は lync.mohsen.com で、Lync サーバーで「asadi」を有効にしたい (「asadi」は LDAP と交換に存在する)

これは私のコードです

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 に答える