public PowershellScriptEndpoint(IPowershellScript PowershellScript) { Post["/script"] = x => { try { var scriptContent = this.Bind <ScriptModel>(); if (scriptContent.text != "") { var command = scriptContent.text; scriptContent.text = PowershellScript.ExecuteScript(command); if (scriptContent.text.Contains("is not recognized")) { return(Negotiate.WithStatusCode(HttpStatusCode.BadRequest) .WithModel(scriptContent)); } return(Negotiate.WithStatusCode(HttpStatusCode.OK) .WithModel(scriptContent)); } return(Negotiate.WithStatusCode(HttpStatusCode.BadRequest)); } catch (Exception) { return(Negotiate.WithStatusCode(HttpStatusCode.InternalServerError)); } }; }
public PowershellScriptEndpoint(IPowershellScript PowershellScript) { Post["/script"] = x => { var scriptContent = this.Bind <ScriptModel>(); if (scriptContent.powerShellScript != "") { var command = scriptContent.powerShellScript; scriptContent.powerShellScript = PowershellScript.ExecuteScript(command); if (scriptContent.powerShellScript.Contains("is not recognized")) { return(Negotiate.WithStatusCode(HttpStatusCode.BadRequest) .WithModel(scriptContent)); } return(Negotiate.WithStatusCode(HttpStatusCode.OK) .WithModel(scriptContent)); } return(Negotiate.WithStatusCode(HttpStatusCode.BadRequest)); }; }