I thought I would post my blog post here to be shared as this is the source of much of my powercli knowledge...thank you.
This is a script for doing exactly what it says, doing BR very easily with PowerCLI.
NFS makes things even easier as you don't have to hassle with presenting LUNs in BR. iSCSI version coming soon!
You basically prepopulate your VM infrastructure in your BR site by adding the VMs on the mirrored datastore to your inventory.
When you need BR, you need to break the storage mirror and then power them on answering the UUID question...all of which is simple with PowerCLI.
@"
===============================================================================
Title: VM-NFSBR.ps1
Description: Connects to vCenter and Powers on all VMs in a specified folder.
Folder name must be unique in vCenter
Answers UUID question to say VM was Moved.
Can be Run as Scheduled Task
Usage: .\VM-NFSBR.ps1
===============================================================================
"@
$vmfolder = "BR-LondonAppServers" # Folder where BR VMs have been placed - Must be unique in VC
$vcserver = "vcenter.local"
# Connect to VC
Connect-VIServer -Server $vcserver
# Get all VMs placed in $vmfolder
$vms = get-vm -Location (get-folder $vmfolder)
# Disconnect Networking FOR TESTING ONLY
#$vms | get-networkadapter | Set-NetworkAdapter -StartConnected:$false -Confirm:$false
# Power on VMs even with questions pending
$vms | Start-VM -RunAsync
# Answer Question to Keep UUID in Loop until Question is answered
$qMsgUuidMoved = "msg.uuid.altered:"
$choiceMove = 2
ForEach ($vm in $vms)
{do
{
$vmview = $vm | Get-View
if($vmview.Runtime.Question -ne $null -and $vmview.Runtime.Question.Text.StartsWith($qMsgUuidMoved))
{
$vmview.AnswerVM($vmview.Runtime.Question.Id, $choiceMove)
}
}
until ($vmview.Runtime.PowerState -ne "poweredoff")
}
# Disconnect from VC Server
Disconnect-VIServer -Confirm:$False