Sponsored Links

 

I created this simple script to make sure all servers stay running when I go on vacation.

It checks the power state and if the server is off it restarts it. Run this as a scheduled task to make sure a server or multiple servers are running.

 

 

 

 

 

-----Copy everything below this line-----

# Created by Chey Harden 3.28.2011

Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer -Server vCENTERSERVERHERE -User LOGINNAMEHERE -Password PASSWORDHERE

$objState = Get-VM SERVERNAMEHERE | Select-Object PowerState

If ($objState -match "ff") {Get-VM SERVERNAMEHERE | Start-VM}

$objState0 = Get-VM 2ndSERVERNAMEHERE | Select-Object PowerState

If ($objState1 -match "ff") {Get-VM 2ndSERVERNAMEHERE | Start-VM}

-----Copy everything above this line-----

  1. Run this from the vCenter Server
  2. You will need VMware vSphere PowerCLI installed on your vCenter Server
  3. Line one invokes the PowerCLI snapin
  4. Line two connects to your vCenter
  5. Line 3 and 4 gets the power state of the server you specify
  6. Line 5 and 6 is optional if you want to add another server
  7. Save as a .ps1 Poweshell script.

 

 

 

This information is provided "AS IS" with no warranties expressed or implied.