tags:

views:

39

answers:

1

Hello,

I was wondering if anyone knew how to use a console file in c#. I tried to run the command through pipeline: "powershell -PSConsoleFile \"C:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1\" -noexit -command \". 'C:\Program Files\Microsoft\Exchange Server\Bin\Exchange.ps1'\""

The issue that I run into is that it brings up the console in my console window and I am not able to run any commands through c# until i exit the console. And then when I try to run the commandlets it cannot find them cause the console was just closed.

So how do I use a console file in C# and run the command ". \"C:\...\""?

Thanks!

A: 

Create your Runspace with a RunspaceConfiguration based on the console file. Use the RunspaceConfiguration.Create static method e.g.:

public static RunspaceConfiguration Create (
    string consoleFilePath,
    out PSConsoleLoadException warnings
)
Keith Hill
Yea I found out you could do that earlier this morning. Lol I also came across the fact that since the only thing the console file had that I actually needed was the Exchange.Management stuff I could use the snap in from that and add the initialization script from exchange by adding it to the runspace configuration thats already on the runspace.
vikt0r