Created
February 24, 2013 22:40
-
-
Save dfinke/5026051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void InvokePowerShell(IDictionary<string, object> env, StreamWriter w) | |
{ | |
string req = env["owin.RequestQueryString"] as string; | |
var queryParts = HttpUtility.ParseQueryString(req); | |
var powerShellFilename = queryParts[null] + ".ps1"; | |
if (File.Exists(powerShellFilename)) | |
{ | |
var script = File.ReadAllText(powerShellFilename); | |
var ps = PowerShell | |
.Create() | |
.AddScript(script); | |
foreach (string item in queryParts) | |
{ | |
if (item != null) | |
{ | |
ps.AddParameter(item, queryParts[item]); | |
} | |
} | |
ps.AddCommand("Out-String"); | |
foreach (var item in ps.Invoke()) | |
{ | |
w.Write(item); | |
} | |
} | |
else | |
{ | |
w.Write(string.Format("{0} not found, cannot execute", powerShellFilename)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment