The term 'Import-Module' is not recognized as the name of a cmdlet


  • Hi Experts.

    I couldn't able to load the lync module in the Csharp ASP.Net Web Service. The module loading code is given below.

    string exchServerAdmin = ""
    string exchServerPwd = "abcd123"

    string url=""
    string shellurl = "";
    PSCredential creds =

    System.Security.SecureString securePassword = new System.Security.SecureString();
    foreach (char c in pwd.ToCharArray())
    creds = new PSCredential(userid, securePassword);                  
    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(url),shellurl, creds);
    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
    RunSpacePool runSpacePool = RunspaceFactory.CreateRunspacePool(1,3, connectionInfo);

    PowerShell pshell = PowerShell.Create();
    pshell.RunspacePool = runSpacePool;

    pshell.AddScript(@"Import-Module Lync");

    IAsyncResult aresult = pshell.BeginInvoke();
    PSDataCollection<PSObject> results = pshell.EndInvoke(aresult);
    if (pshell.Streams.Error != null && pshell.Streams.Error.Count == 0)
         logger.Debug(operation + "Reslts   " + results.Count);
         logger.Debug(operation + "ProcessResponse Executed Successfully " + results.Count);
           if (pshell.Streams.Error != null)
               System.Text.StringBuilder builder = new System.Text.StringBuilder();
               logger.Error(operation +" Errors occured");
               foreach (ErrorRecord error in pshell.Streams.Error)



    I am getting the following exception while running the above code while loading the Lync module. The exception details are given below.

    System.Management.Automation.RemoteException: The term 'Import-Module' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    Any Idea Why this Exception is throwing.


    Help is Greatly appreciated.

    Friday, November 18, 2011 1:03 AM

All replies

  • Ameer,

    Do you want to run the Lync Management Shell commands or something else?

    If you do, the needed module lies here:

    C:\Program Files\Common Files\Microsoft Lync Server 2010\Modules\Lync\Lync.psd1

    Maybe a full command that runs Management Shell would help:

    C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "cd $env:UserProfile; Import-Module 'C:\Program Files\Common Files\Microsoft Lync Server 2010\Modules\Lync\Lync.psd1'

    Try to cd $env:UserProfile first
    Friday, November 18, 2011 1:08 PM