PoshCode Archive  Artifact Content

Artifact cd98beb0dddcd92c244a7c642726b6020e0160fad37c31054f868e012421f286:

  • File Set-FT.ps1 — part of check-in [474aaf9521] at 2018-06-10 12:56:53 on branch trunk — Script used to turn FT on or off for a specific VM (user: unknown size: 895)

# encoding: ascii
# api: powershell
# title: Set-FT
# description: Script used to turn FT on or off for a specific VM
# version: 0.1
# license: CC0
# x-poshcode-id: 1336
# x-archived: 2009-09-28T13:58:54
#
#
#Some Parameters
param([string]$ftVM, [string]$ftState)

#Load the PowerCLI Snapin
add-pssnapin VMware.VimAutomation.Core

#Load the creds file
$creds = Get-VICredentialStoreItem -file c:\test 

#Connect to the host
connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password

#Based on $ftState, turn FT on or off for $ftVM
$ftState = $ftState.ToLower()
if ($ftState -eq "on"){
	#Turn FT On
	Get-VM X | Get-View | % { $_.CreateSecondaryVM($null) }
} elseif ($ftstate -eq "off"){
	#Turn FT Off
	Get-VM X | Select -First 1 | Get-View | % { $_.TurnOffFaultToleranceForVM() }
} else {
	Write-Error "FT State must be either On or Off"
}