stop HyperV VM by WMI in powershell

来源:互联网 发布:张鲁农村淘宝网 编辑:程序博客网 时间:2024/06/11 20:09

A script used to stop HyperV VM

######stop HyperV VM by name #############Usage: stopvm.ps1 #############please run: "set-executionpolicy RemoteSigned" if you cannot execute this script #######param ([string]$VMName)$vm = Get-WmiObject -Namespace root\virtualization -Query “Select * From Msvm_ComputerSystem Where ElementName=’$VMName’”echo “vm =” $vm$VMGUID = $vm.Name$sc = Get-WmiObject -Namespace root\virtualization -Query “Select * from Msvm_ShutdownComponent where SystemName = ‘$VMGUID’”echo “sc = ” $scecho “call InitiateShutdown”$sc.InitiateShutdown(“TRUE”, “test shutdown”)

For more details, Go to https://www.hyzblog.com/memory-leak-in-iis/




                                             
0 0
原创粉丝点击