Information Technology Reference
In-Depth Information
}
}
If($Console = $true){
Write-Host “from $sourcehost to $DestHost”
}
# Set Variables needed for CheckMigrate Method
$pool = ($v.ResourcePool).ExtensionData.MoRef
$vmMoRef = $v.ExtensionData.MoRef
$hsMoRef = $DestHost.ExtensionData.MoRef
$si = Get-View ServiceInstance -Server $global:DefaultVIServer
$VmProvCheck = get-view $si.Content.VmProvisioningChecker
$result = $VmProvCheck.CheckMigrate( $vmMoRef, $hsMoRef, $pool, $null, $null )
# Organize Output
$Output = “” | Select VM, SourceHost, DestinationHost,`
Error, Warning, CanMigrate
$Output.VM = $v.Name
$Output.SourceHost = $sourcehost
$Output.DestinationHost = $DestHost.Name
# Parse Error and Warning messages
If($result[0].Warning -ne $null){
$Output.Warning = $result[0].Warning[0].LocalizedMessage
$Output.CanMigrate = $true
If($Console = $true){
Write-Host -ForegroundColor Yellow`
“$v has warning but can still migrate”
}
}
If($result[0].Error -ne $null){
$Output.Error = $result[0].Error[0].LocalizedMessage
$Output.CanMigrate = $False
If($Console = $true){
Write-Host -ForegroundColor Red “$v has error and can not migrate”
}
}Else {
$Output.CanMigrate = $true
If($Console = $true){
Write-Host -ForegroundColor Green “$v is OK”
}
}
$report += $Output
#This resets the Destination Host to the preferred host
#in case it had to be changed.
If($VMHost -ne $null){
$DestHost = Get-VMHost $VMHost
}
Search WWH ::




Custom Search