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.