基于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

 

posted @ 2013-07-24 16:37  zleaves  阅读(477)  评论(0编辑  收藏  举报