You can start, stop and restore virtual machines easily using PowerShell. In the next couple of posts I will start, stop and restore virtual machines using PowerShell.
You can add the VMM snapin with ‘Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager’ if you dont want to use ‘Windows PowerShell – Virtual Machine Machiner’
Before you can utilize PowerShell with VMM you need to connect to the server. You connect to the server with ‘Get-VMMServer -ComputerName “<ComputerName> | out-null”’
You now made connection with the VMM server and you are ready to start the virtual machine. Enter ‘start-VM –VM <ComputerName> | out-null’ to stop the virtual machine.
That’s all there is to start your virtual machines. This script is quite simple and there are no special things in this post.
foreach($Server in $serverarray) { $SelectedVM = get-VM -Name $Server </span><span style="color: #000000;"> #Start VM’s Start-VM -VM $SelectedVM | out-null </span> <span style="color: #000000;"> do { start-sleep -seconds 3 Write-Host “$server is starting” -foregroundcolor cyan } </span> <span style="color: #000000;"> until($selectedVM.status -eq “Running”) Write-Host “$server turned on successfull” -foregroundcolor green </span> <span style="color: #000000;">}
You can add additional features like an array with all your servers that you want to start, stop or restore.
You probably dont want to start multiple servers at the same time. With a simple do statement you can wait for every server to start properly.
do { Write-Host “$server is starting” -foregroundcolor cyan start-sleep -seconds 3 } until($selectedVM.status -eq “PowerOff”)