基於C#的Lync Server管理

這裏所說的Lync Server管理,指通過C#管理Lync賬號的啓用,禁用,開啓賬戶的語音功能。

Lync服務器安裝後,會自動創建一個用於遠程管理的應用程序,通過IIS查看,其應用程序名爲:

Lync Server Internal Web Site下邊的OcsPowershell,通過瀏覽他的目錄可以看出,這個是Lync用於遠程執行管理命令的一個WebService,準備工作做好之後,接下來就可以測試連接。

1、引用System.Management.Automation.dll

項目依賴於這個dll,地址在:C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll,這個應該是電腦安裝了Power Shell纔會有的;

2、創建遠程運行空間

 

using System.Management.Automation;

using System.Management.Automation.Runspaces;

using System.Management.Automation.Host;

public class RemoteRunspace : IRunspace

{

public Runspace CreateRunspace()

{

//Lync管理webservice地址

String uri = "https://服務器名/OcsPowerShell";

//命令解析uri

String shellUri = "http://schemas.microsoft.com/powershell/Microsoft.Powershell";

//管理賬戶

String userName = "xxx";

//管理密碼

String userPwd = "xxx";

Char[] userPwds = userPwd.ToCharArray();

SecureString secPwd = new SecureString();

foreach (Char c in userPwds)

{

secPwd.AppendChar(c);

}

RunspaceConfiguration config = RunspaceConfiguration.Create();

WSManConnectionInfo connInfo = new WSManConnectionInfo(new Uri(uri), shellUri, new PSCredential(userName, secPwd));

Runspace runspace = RunspaceFactory.CreateRunspace(connInfo);

try

{

runspace.Open();

Console.WriteLine("創建Remote Runspace成功!");

return runspace;

}

catch (Exception ex)

{

Console.WriteLine(ex.ToString());

return null;

}

}

}
3、遠程運行空間創建成功後,就可以創建管理,運行Lync管理命令
Pipeline pipe=runspace.CreatePipeline();

Command cmd = new Command("Get-CsUser");

cmd.Parameters.Add("identity", "test");

pipe.Invoke();

現在我們可以通過這種方式,遠程執行各種管理命令,而不需要再登陸到Lync服務器。

Exchange服務器的管理類似Lync,這方面微軟做的還是不錯的。 4、常用的Lync管理命令

啓用:Enable-CsUser -Identity xx -RegistrarPool (lync註冊池) -SipAddressType

禁用:Disable-CsUser -identity xx

開啓語音功能:Set-CsUser -identity xx -EnterpriseVoiceEnable $true -LineURI "TLE:xx"

更多管理命令請參考:

http://technet.microsoft.com/zh-CN/library/gg398306.aspx

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章