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();
}
根据您在此处显示的内容,我看不出您使用明确的努力的原因。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.