?????????????Lync Server?????????C#????Lync???????????????????????????????

????Lync????????????????????????????????????ó??????IIS????????ó????????

????Lync Server Internal Web Site?±??OcsPowershell????????????????????????????Lync?????????й???????????WebService??????????????????????????????????

????1??????System.Management.Automation.dll

????????????????dll????????C:Program FilesReference AssembliesMicrosoftWindowsPowerShellv1.0System.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;
}
}
}