I'm trying to restart an iis app pool on a remote server. First I would like to stop the app pool however I am getting an
Cannot convert the "{ Stop-WebAppPool -Name "BaymentPool" }" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
exception
public void StopAppPool() { Runspace runSpace = RunspaceFactory.CreateRunspace(); runSpace.Open(); Pipeline pipeline = runSpace.CreatePipeline(); Command invokeCmd = new Command("Invoke-Command"); invokeCmd.Parameters.Add("ComputerName","IISC02"); invokeCmd.Parameters.Add("ScriptBlock","{ Stop-WebAppPool -Name \"BaymentPool\" }"); pipeline.Commands.Add(invokeCmd); Collection<PSObject> output = pipeline.Invoke(); foreach (PSObject psObject in output) { Process process = (Process)psObject.BaseObject; Console.WriteLine("Process name: " + process.ProcessName); } } I can't quite fathom out what I am doing wrong. I know I need to add each param separately, which I think I'm doing, however it still complains.