c# - Using Powershell in an ASP.NET application deployed to an IIS server -
i'm developing test project in asp.net mvc, im using system.management.automation execute powershell cmdlets. of cmdlets azure powershell module.
the code working fine when run visual studio. when published website iis cmdlets , these scripts don't work.
example, see comments before:
var shell = powershell.create(); var script1 = "get-azuresubscription | out-string"; // cant execute cmdlet var script2 = "c:\\inetpub\\wwwroot\\app1\\scripts\\test.ps1"; //cant execute script. var script3 = "get-date"; //work fine try { shell.commands.addscript(script); // here insert script. collection<psobject> results = shell.invoke(); //search errors, if error found redirect error page. if (shell.streams.error.count > 0) { foreach (errorrecord err in shell.streams.error) { string error = err.tostring(); tempdata["pserror"] = error; return redirecttoaction("powershellerror"); } } else if (results.count > 0) { foreach (var psobject in results) { string result2 = psobject.tostring(); tempdata["psoutput"] = result2; return redirecttoaction("powershelloutput"); } }
both, script1 , script2 give error:
the term 'c:\inetpub\wwwroot\app1\scripts\test.ps1' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify path correct , try again.
and
the term 'get-azuresubscription' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify path correct , try again.
what be??? missing in iis setup?
you need import azure module, try suggested here:
https://stackoverflow.com/a/6267517/1183475
var ps = powershell.create(myrs); ps.commands.addcommand("import-module").addargument(@"g:\...\powerdbg.psm1") ps.invoke()
i don't have azure ps tools installed on machine, path should be: "c:\program files (x86)\microsoft sdks\windows azure\powershell\azure\azure.psd1
Comments
Post a Comment