Hi guys. Happy New Year. Has anyone tried running the powershell script that Netapp has graciously shared in the Netapp Best Practices for MS Virtualization TR3702 doc? They've developed a pretty cool scipt that pretty much automates the whole process of mounting a VM after you have replicated over to your DR SAN. I have modified the pwershell script so that it fits out environment but I am having some issues where it will not map the LUN. Below is the script. Also, has anyone run into the NIC IP address dissapearing after replicating over from production to DR SAN & mounting VM on a different Hyper-V Parent server? The issue we are seeing is that the VM's IP address dissapears as the GUID for the virtual adapter is different in the DR Hyper-V Parent server. We're trying to script this and making it seamless but we're having difficulties. Is anyone else out there working on a Hyper-V environment, using Snapmirror replication to mirror VMs across to DR SAN? Please let me know your experiences. Thanks.
Script Below:
# Purpose – To failover storage to Secondary NetApp storage system and Recover all VMs automatically
# Tools - PowerShell, plink (SSH Communication)
# Posted: January 2010
$DRFiler = Read-Host "SAN"
$VolName = Read-Host "VOL"
$LUNName = Read-Host "VM"
$VMVHD = Read-Host "VM.VHD"
$iqn = "iqn.1991-05.com.microsoft:server.domain.com"
$LUNPath = $DRFiler + ":" + "/vol/" + $VolName + "/" + $LUNName
function Create_VM ( $VM_Service, $VMName )
{
$wmiClassString = "\\" + "LocalHost" + "\root\virtualization:Msvm_VirtualSystemGlobalSettingData"
$wmiClass = [WMIClass]$wmiClassString
$newVSGlobalSettingData = $wmiClass.CreateInstance()
while ($newVSGlobalSettingData.psbase.Properties -eq $null) {}
# Set the VM name
$newVSGlobalSettingData.psbase.Properties.Item("ElementName").value = $VMName
$status = $VM_Service.DefineVirtualSystem($newVSGlobalSettingData.psbase.GetText(1))
if ($status.ReturnValue -eq 0)
{
$NewVM_PATH = $status.DefinedSystem
return $NewVM_PATH
}
}
function Attach_VHD ( $VM_Service, $NewVM_PATH, $VHD )
{
$ListOfControllers = get-wmiobject -namespace root\virtualization Msvm_ResourceAllocationSettingData |
where-object {$_.ResourceSubType -like "*Emulated*IDE*"}
foreach ($Controller in $ListOfControllers)
{
if ($Controller.Address -eq 0)
{
$IDEController0 = $Controller
}
}
$DiskDefault = get-wmiobject -namespace root\virtualization Msvm_ResourceAllocationSettingData |
where-object {($_.ResourceSubType -like "Microsoft Synthetic Disk Drive") –and ($_.InstanceID -like '*Default*')}
$DiskDrive = $DiskDefault.psbase.Clone()
$DiskDrive.Parent = $IDEController0.__PATH
$DiskDrive.Address = 0
$Status = $VM_Service.AddVirtualSystemResources($NewVM_PATH, $DiskDrive.psbase.GetText(1))
if ($Status.ReturnValue –eq 0)
{
$NewDiskDrive_PATH = $Status.NewResources
}
$VHDDefault = get-wmiobject -namespace root\virtualization Msvm_ResourceAllocationSettingData |
where-object {($_.ResourceSubType -like "Microsoft Virtual Hard Disk") –and ($_.InstanceID -like '*Default*' )}
$NewDiskDrive = [WMI]"$NewDiskDrive_PATH"
$VHDisk = $VHDDefault.psbase.Clone()
$VHDisk.Parent = $NewDiskDrive.__PATH
$VHFile = $VHD
$VHDisk.Connection = $VHFile
$VM_Service.AddVirtualSystemResources($NewVM_PATH, $VHDisk.psbase.GetText(1))
}
Write-Host " Select:
1 - Perform Recovery on the same Hyper-V Host
2 - Perform Recovery to a different Hyper-V Host
* - Exit the script"
$Choice = Read-Host "Enter the selection"
$fqdn = hostname
if ($Choice -eq 1)
{
Write-Host "Performing recovery on the same Hyper-V Host can imply that
it is not required to recreate the VM Configuration, provided
the recovered LUN is attached with the same Drive Letter
as it was before the Disaster"
sdcli sysconfig list | select-string -pattern "Available drive letters" -CaseSensitive
Write-Host "Ensure that the Drive Letter is in the available list in case the prior configuration is retained"
Write-Host ""
$Decide = Read-Host "Would you like to specify the same Drive as per configuration prior to disaster (y / n)"
Write-Host ""
if ($Decide -eq 'y')
{
$DriveLetter = Read-Host "Select an available Drive Letter from the above list""
sdcli disk connect -p $LUNPath -d $DriveLetter -I $fqdn $iqn -dtype dedicated
sleep -Seconds 4
Write-Host "Now start the VM and check its status"
}
elseif ($Decide -eq 'n')
{
$DriveLetter = Read-Host "Select an available Drive Letter from the above list"
sdcli disk connect -p $LUNPath -d $DriveLetter -I $fqdn $iqn -dtype dedicated
$VMName = $DRFiler + "-" + $VMVHD.trimend('.vhd')
$VHD = $DriveLetter + ":\" + $VMVHD
$VM_Service = Get-WmiObject –namespace root\virtualization
Msvm_VirtualSystemManagementService
$NewVM_PATH = Create_VM $VM_Service $VMName
Attach_VHD $VM_Service $NewVM_PATH $VHD
}
else
{
Write-Host "Invalid Input. Rerun the script and Enter Y or N"
exit
}
}
elseif ($Choice -eq 2)
{
$DriveLetter = Read-Host "Select an available Drive Letter from the above list"
sdcli disk connect -p $LUNPath -d $DriveLetter -I $fqdn $iqn -dtype dedicated
$VMName
$VMVHD
$VM_Service = Get-WmiObject –namespace root\virtualization Msvm_VirtualSystemManagementService
$NewVM_PATH = Create_VM $VM_Service $VMName
Attach_VHD $VM_Service $NewVM_PATH $VHD
}
else
{
exit
}