PowerShell run from C# to start/stop IIS application pools has no effect -


i'm stuck @ little piece of code 2 days now. have c# helper class execute powershell scripts. use powershell.create() initialize instance of powershell, use addscript write commands, , call invoke method synchronously.

now i'm trying stop windows service, , iis application pool. windows service stopped, no effect on iis application pool.

using (var powershell = powershell.create()) {     // powershell doesn't stop application pool     powershell.addscript("stop-webapppool -name application_name");      // stops windows service     powershell.addscript("stop-service service_name");      var result = powershell.invoke(); } 

both scripts work when execute them via ise. problem is? think miss powershell.

you can use this

  using (powershell shell = powershell.create())         {             shell.addscript(@"import-module webadministration;");             shell.addscript(@"stop-website -name 'default web site';");             shell.addscript(@"stop-webapppool -name 'defaultapppool';");             shell.invoke();              if (shell.haderrors)             {                 foreach (errorrecord _errorrecord in shell.streams.error)                 {                     console.writeline(_errorrecord.tostring());                 }             }         } 

Comments