none
Powershell Automation & Import-Module command RRS feed

  • Question

  • I've been bouncing around the different fora for this - nobody wants to be the home of powershell automation techniques :(

    Anyway.. here's what I'm doing - running Powershell commandlets from C# code (as per the codeproject article). Besides running the base commandlets, I've also successfully hooked into the Exchange 2007 Add-Ins (when they're installed on the local machine) as well as remotely connected to a Lync server to call the Lync commandlets.

    In the latter case,you open a runspace by providing a WSManConnectionInfo object as follows

    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
          new Uri(ocsuri));

    Where ocsuri = https://your-lync-server/ocspowershell.

    This allows you to immediately run the lync powershell commandlets.

    Similarly, against Exchange you'd connect using the syntax

    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
          new Uri(liveIdconnectionUri),
          http://schemas.microsoft.com/powershell/Microsoft.Exchange,
          credential);

    connect.

    Once I've opened the runspace in both instances, I can then open as many pipelines as I want and I can always use the product specific commandlets immediately.

    Now I'd like to call the active directory management powershell commandlets. Running the powershell commandline, I only get access to the AD specific modules if I type

    "Import-Module ActiveDirectory".

    Once done, I get all the AD specific commandlets. But, I'm looking for a way to have those available without having to call "Import-Module"... in my code I open the runspace, keep it, then create a bunch of pipelines and invoke on those.

    There's no need for importing modules for both Exchange and Lync if you start the runspace appropriately - and I'm looking for a way to translate what I'm doing against Exchange and Lync to work against the AD powershell commandlets as well.

    As I've initially mentioned, this issuse has been bounced all over so in the interest of time, here are the previous threads: http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/01409465-5c32-42c3-a8ae-276ea9731d00

    http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/26b3011c-be81-4030-b2a9-6e38d5979311

    • Moved by Larcolais Gong Sunday, April 17, 2011 12:41 PM (From:Visual C# General)
    Thursday, April 7, 2011 2:27 PM

All replies