PowerCLI Move All VM’s to other Host

################### Config ##################################

$SourceVC = 20;.

################## PASSWORD STORE #########################

#Username

# Check if credentials exist in credential store if not ask for credentials and put them in credential store

 

If ((Get-VICredentialStoreItem).host -notcontains $SourceVC) {New-VICredentialStoreItem -Host $SourceVC -User $env:USERNAME -Password ((get-credential).GetNetworkCredential().Password)}

 

# Remove-VICredentialStoreItem * -Confirm:$

 

#################### END INIT ####################################

 

#Login to vCenter servers

if (($global:DefaultVIServers).Name -notcontains $SourceVC) {

 

#SourceVC

$ConnectVC = Connect-VIServer $SourceVC

 

# Get-Cluster –Name $DestinationCluster – $DestinationVC | Get-VMhost -State Connected | Sort-Object -Property MemoryUsageGB | Select-Object -First 1

 

$ESXiHostSrc = “01.wardvissers.nl”

$ESXiHostDst = “esx02.wardvissers.nl”

$vmList = Get-VMHost $ESXiHostSrc | Get-

$vmList | -destination (get-vmhost $ESXiHostDst)

}