Information Technology Reference
In-Depth Information
$VM = $null
}
If($VMHost -ne $null){
$DestHost = Get-VMHost $VMHost
If(($DestHost.ConnectionState -ne “Connected”) -or`
($DestHost.PowerState -ne “PoweredOn”)){
Return “You must provide a target host that is Powered on and`
not in Maintenance Mode or Disconnected”
}
}
$singlevm = $false
$targetcluster = Get-Cluster $Cluster
$vms = $targetcluster | Get-VM | `
Where{$_.PowerState -eq “PoweredON”} | Sort-Object
$vmhosts = $targetcluster | Get-VMHost | Where{($_.ConnectionState -eq “Connected”)
-and ($_.PowerState -eq “PoweredOn”)}
If ($vmhosts.Count -lt 2){
Return “You must provide a target host that is not`
the source host $sourcehost”
}
$count = $vms.Count
If($Console = $true){
Write-Host “Checking $count VMs in cluster $cluster”
}
} ELSE {
$vms = Get-VM $VM
If($VMHost -eq $null){
$DestHost = Get-Cluster -VM $vms | Get-VMHost | `
Where{($_.ConnectionState -eq “Connected”) -and `
($_.PowerState -eq “PoweredOn”)} | Get-Random | Where{$_ -ne $vms.VMhost}
} ELSE {
$DestHost = Get-VMHost $VMHost
}
$singlevm = $true
}
# Functional Loop
foreach($v in $vms) {
If($Console = $true){
Write-Host “-------------------------”
Write-Host “Checking $v ...”
}
$sourcehost = $v.VMhost
If($singlevm -eq $false){
While(($DestHost -eq $null) -or ($DestHost -eq $sourcehost)){
#Select random host from the cluster in the event that Source and Destination
#are the same or Destination is Null.
$DestHost = $vmhosts | Get-Random | Where{($_ -ne $sourcehost)`
-and ($_ -ne $null)}
Search WWH ::




Custom Search