2015-01-28 2 views
0

У меня есть код, который пытается получить сеанс lync с использованием сценария сценария powershell C#. При попытке запустить скрипт «$ CSSession = New-CsOnlineSession -Credential $ cred \ n" Я получаю исключение для исключения ссылок.Исключительное исключение ссылки в Microsoft.Rtc.Admin.AuthenticationHelper при попытке запустить скрипт powershell

Трассировка стека:

System.Management.Automation.CmdletInvocationException был необработанное
HResult = -2146233087 = Сообщение объекта не задана ссылка на экземпляр объекта. Источник = System.Management.Automation
WasThrownFromThrowStatement = ложь StackTrace: на System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate (Object ввода, Hashtable errorResults, логическое перечисление) в System.Management.Automation.PipelineOps.InvokePipeline (входного объекта, Boolean ignoreInput, CommandParameterInternal [] [] pipeElements, CommandBaseAst [] pipeElementAsts, CommandRedirection [] [] commandRedirections, FunctionContext funcContext) в System.Management.Automation.Interpreter.ActionCallInstruction`6.Run (InterpretedFrame кадра) в System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.R ип (InterpretedFrame кадр) на System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run (InterpretedFrame кадр) InnerException: System.NullReferenceException HResult = -2147467261 = Сообщение объекта не задана ссылка на экземпляр объекта. Источник = Microsoft.Rtc.Admin.AuthenticationHelper StackTrace: в Microsoft.Rtc.Admin.Authentication.ManagedIdcrl..ctor (режим IDCRLMode) на Microsoft.Rtc.Admin.Authentication.ManagedIdcrl..ctor() в Microsoft .Rtc.Management.LyncOnlineConnector.GetWebTicketCmdlet.CreateAndInitializeManagedIdcrl() на Microsoft.Rtc.Management.LyncOnlineConnector.GetWebTicketCmdlet.get_ManagedIdcrl() в Microsoft.Rtc.Management.LyncOnlineConnector.GetWebTicketCmdlet.GetLiveIdToken (Строка remoteFqdn, Int32 порт, PSCredential кредитки) в Microsoft.Rtc.Management.LyncOnlineConnector.GetWebTicketCmdlet.ConnectToWebTicketService (String fqdn, порт Int32, PSCredential creds)на Microsoft.Rtc.Management.LyncOnlineConnector.GetWebTicketCmdlet.BeginProcessing() в System.Management.Automation.Cmdlet.DoBeginProcessing() в System.Management.Automation.CommandProcessorBase.DoBegin() InnerException:

кодекс:

public static void GetLyncUsers(string userName, string plainPassword) 
    { 
     RunspaceConfiguration config = RunspaceConfiguration.Create(); 
     using (Runspace myRs = RunspaceFactory.CreateRunspace(config)) 
     { 
      myRs.Open(); 

      RunspaceInvoke scriptInvoker = new RunspaceInvoke(myRs); 
      scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted"); 

      using (PowerShell powerShellInstance = PowerShell.Create()) 
      { 
       powerShellInstance.Runspace = myRs; 

       // Import module. 
       powerShellInstance.Commands.AddCommand("Import-Module") 
        .AddArgument(
         @"C:\Program Files\Common Files\Microsoft Lync Server 2013\Modules\LyncOnlineConnector\LyncOnlineConnector.psd1"); 
       powerShellInstance.Invoke(); 
       powerShellInstance.Commands.Clear(); 


       // Set credentials 
       SecureString password = new SecureString(); 
       foreach (var passChar in plainPassword) 
       { 
        password.AppendChar(passChar); 
       } 

       PSCredential credential = new PSCredential(userName, password); 
       powerShellInstance.AddCommand("Set-Variable"); 
       powerShellInstance.AddParameter("Name", "cred"); 
       powerShellInstance.AddParameter("Value", credential); 
       powerShellInstance.Invoke(); 
       powerShellInstance.Commands.Clear(); 

       // Run the script 
       var script = string.Format(
        "$CSSession = New-CsOnlineSession -Credential $cred\n"); 
       powerShellInstance.AddScript(script); 
       Collection<PSObject> psOutput = powerShellInstance.Invoke(); //Getting exception here. 

       // check the other output streams (for example, the error stream) 
       if (powerShellInstance.Streams.Error.Count > 0) 
       { 
        // error records were written to the error stream. 
        // do something with the items found. 
       } 
      } 
     } 

    } 

ответ

0

мне сказали мои MS подтверждают, что применение Lync Online PowerShell скрипт из C# в настоящее время не поддерживается.

Смежные вопросы