I want to execute a set of powershell commands to manage my HyperV Guest machine. Can I use the below code to do this ? Do I need to clear pipeline.Commands before executing the next command ?
Collection<PSObject> results = null;
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Shutdown-VM ADServer-01");
results = pipeline.Invoke();
//Do I need pipeline.Commands.Clear();
pipeline.Commands.AddScript("Get-VMState ADServer-01");
results = pipeline.Invoke();
runspace.Close();
}