Quantcast
Channel: Forum Microsoft Identity Manager
Viewing all articles
Browse latest Browse all 4767

Powershell not running within an ECMA

$
0
0

Hello FIM friends,

I'm trying to embed a simple PS call within an ECMA to enable Lync accounts. I have a form app that works perfectly and can enable the accounts from the cmd line shell using the FIM service account, but the call fails when being run from within the MA.

Here's the method I'm using:

 
public void enableLync(String cn)
 {
   String pool = getParams("Pool");
   String sipAddress = getParams("SIPAddress").Replace("cn", cn);

   InitialSessionState initial = InitialSessionState.CreateDefault();
   initial.ImportPSModule(new string[] { "C:\\Program Files\\Common Files\\Microsoft Lync Server 2010\\Modules\\Lync\\Lync.psd1" });
   Runspace runspace = RunspaceFactory.CreateRunspace(initial);
   runspace.Open();
   PowerShell ps = PowerShell.Create();
   ps.Runspace = runspace;

   //Enable the user for Lync
   ps.Commands.AddCommand("Enable-CsUser");
   ps.AddParameter("-Identity", cn);
   ps.AddParameter("-RegistrarPool", pool);
   ps.AddParameter("-SipAddress", sipAddress);

   ps.Invoke();

 }

The error is "System.Management.Automation.CommandNotFoundException: The term 'Enable-CsUser' is not recognized as the name of a cmdlet, function, script file, or operable program"

Which looks like a permissions issue, or the "ImportPSModule" call is failing - but I can Import the Lync module fine from the PS cmd line and my test app runs the exact same code as above perfectly well when both are runas the FIM Service account. 

Has anyone come across anything like this before? Any ideas?

Cheers,

Dave


Viewing all articles
Browse latest Browse all 4767

Trending Articles



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