views:

137

answers:

1

I have a c# app which executes rules, depending on an input. Some of the rules need to execute a poweshell script. I would assume that some of the scripts, as perhaps writtem by a user, would need a snapin to be available before they can execute correctly.

I know I can add the snap in by doing something like this.

RunspaceConfiguration config = RunspaceConfiguration.Create(); PSSnapInException warning; config.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning); if (warning != null) { ... throw warning; }

I also know that the snapin metadata can be stored in a powershell .psc1 console file, if it has been setup by the use. I can load this. But what if the user does not have a console file, and only wants to use a single snapin from IIS, or Exchange, or perhaps from a custom snapin.

What is the best way of storing the definition. Could I store it in app.config. Say the script needed 'WebAdministration' which is the IIS 7 snapin name. Could I just store that in a a key in app.config. I would read it, and load it, as above.

Is there anything I am missing here. Any help would be appreciated. Thanks. Bob.

+2  A: 

Taking your example of webadministration, the user should be declaring this as a requirement in the script itself (which you can parse out later)

#requires -pssnapin WebAdministration
$foo = get-web

http://technet.microsoft.com/en-us/library/dd315380.aspx

x0n
Thank x0n, Seems a simple and easy way of doing it.Bob.
scope_creep
if you think so, mark as answer please ;)
x0n