none
Powershell not running within an ECMA RRS feed

  • Question

  • 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

    Thursday, December 4, 2014 10:32 AM

Answers

  • OK, I've solved it - it helps if the path to the Lync module is correct! I have Lync 2013 (not 2010) on my dev machine. Why my Form-based app works with the same (incorrect) path to the module is a mystery though.

    Dave

    • Marked as answer by Dave Nesbitt Thursday, December 4, 2014 12:46 PM
    Thursday, December 4, 2014 12:46 PM