powershell 2 0 shutdown vm script

MOBS Bangladesh Meeting of Brilliant Syche - IT Pro's Corner http://mobs-bd.org PowerShell 2.0 - ShutDown VM Scrip...

2 downloads 119 Views 34KB Size
MOBS Bangladesh Meeting of Brilliant Syche - IT Pro's Corner http://mobs-bd.org

PowerShell 2.0 - ShutDown VM Script Author : Shuvro Here is the script for shutting down a Virtual Machine. Have a close look in the script and look for change needed, like your virtual machine name, exit reasons etc. This script is tested under Win2k8 and Win2k8R2 Environment. Thanks goes to the person who wrote this, I can't remember his/her name or where I collected this script, but had it for a long time now, and used it regularly; now sharing this small script with you all. # Shutdown a Virtual Machine (requires Integration Components) param ([string]$vmName = $(throw "Must specify virtual machine name") ) # Get the VM by name and request state to change to Enabled $vm = gwm i -namespace root\virtualization Msvm_ComputerSystem -filter "Elemen tName='$vmName'" # Get the associated Shutdown Component $shutd own = gwmi -namespace root\virtualization ` -query "Associators of {$vm} where ResultClass=Msvm_ShutdownComponent" # Initiate a forc ed shutdown with simple reason string, return resulting error code return $shutdown.InitiateShutdown($true,"System Maintenance")

1/1 Powered by TCPDF (www.tcpdf.org)