Start and Stop VMWare virtual machines using powershell

Install PowerCLI from the VMWare support site

Create file shutdown.ps1

Add-PSSnapin Vmware*
Connect-VIServer -server XXX -user XXX@vsphere.local -password XXXX
$vmservers = Get-VM | Where-Object { $_.Name -like 'VICI-*' -and $_.PowerState -eq 'PoweredOn' }
$vmservers | select Name | export-csv c:\temp\viciservers.csv -NoTypeInformation
$vmservers | Stop-VMGuest -Confirm:$false 

Create file startup.ps1

Add-PSSnapin Vmware*
Connect-VIServer -server XXX -user XXX@vsphere.local -password XXXX
$vmservers = import-csv C:\temp\viciservers.csv | select -ExpandProperty name
Start-VM -VM $vmservers

*NOTE make sure you replace the XXX's with the appropriate values.

Start Task Scheduler
Create a new basic task
For the program name put "powershell"
For the parameter put -file "c:\xxxx.ps1"
Schedule each file and thats it.

Comments are closed.