Quantcast
Channel: Microsoft Unified Communications Managed API SDK forum
Viewing all articles
Browse latest Browse all 889

Could not call Lync Server 2013 Powershell cmdlets from C#

$
0
0

Hi all:

   I made a test programe that run Lync 2013 cmdlet from C#, but failed, the error as following:

   system.management.automation.commandnotfoundexception

  at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandOrigin commandOrigin)

   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)

   at System.Management.Automation.ExecutionContext.CreateCommand(String command)

...

  The code is same as the demo code in MS site as following and the same code could run in Lync 2010 environment:

   http://msdn.microsoft.com/en-us/library/lync/hh364912.aspx

using System;using System.Collections.ObjectModel;using System.Management.Automation;using System.Management.Automation.Runspaces;namespace Microsoft.Rtc.Collaboration.Sample.ApplicationActivation {class Program {staticvoid Main(string[] args) {// Get the operating environment to run commands. InitialSessionState iss = InitialSessionState.CreateDefault(); iss.ImportPSModule(new[] { "Lync" });using (Runspace myRunSpace = RunspaceFactory.CreateRunspace(iss)) { myRunSpace.Open();// Execute the Get-CsTrustedApplication cmdlet.using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create()) { powershell.Runspace = myRunSpace; powershell.AddCommand("Get-CsTrustedApplication"); Collection<PSObject> results = null; Collection<ErrorRecord> errors = null;try { results = powershell.Invoke(); errors = powershell.Streams.Error.ReadAll(); }catch (Exception ex) {// An error occurred running the cmdlets.// TODO (Left to the reader): Error handling code.throw; }if (errors.Count != 0) {// Errors were reported by the cmdlets.// TODO (Left to the reader): Error handling code. }foreach (PSObject result in results) { Console.WriteLine("Identity\t: "+ result.Members["Identity"].Value); Console.WriteLine("ApplicationId\t: "+ result.Members["ApplicationId"].Value); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } } } } }

Could anyone help with this issue?

Thanks


Viewing all articles
Browse latest Browse all 889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>