Hi and thanks in advance for the help. I need to use power cli to move a vm if it resides on a certain esxhost (we are storage migrating some VM's and if they reside on a problematic host it crashes) could anybody please assist with this line?
Thanks
Jim
Something like this?
$newDS = '???'
Get-VM -Name (Get-Content -Path '.\vmnames.txt') -PipelineVariable vm |
ForEach-Object -Process {
if($problemEsx -notcontains $vm.VMHost.Name){
Move-VM -VM $vm -Datastore $newDS -Confirm:$false
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this.
For the target ESXi node you have multiple options. This example just picks another ESXi node.
$tgtEsx = 'MyEsx'
Get-VMHost -Name $esxName | Get-VM | Move-VM -Destination $tgtEsx -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the info
That would effectively be the wrong way round. I simply want to move vm If not in problem esx host. If on problem host cancel resquest
So you want to move the VM when it is not on the problematic ESXi node?
Where do you want to move it to? The problematic ESXi node?
If yes, replace $tgtEsx by $esxName on the Move-VM cmdlet.
You could do
$tgtEsx = 'MyEsx'
Get-VMHost | where{$_.Name -ne $esxName} |
Get-VM | Move-VM -Destination $tgtEsx -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So what I need to do is to storage vmotion vm. It we have 3 problem esx hosts. Should the vms reside on one of those hosts and we storage vmotion the host fails so we want to check if vms is on bad host, vmotion vm to a good host then storage vmotion
thabks I advance
Your description is rather confusing I'm afraid.
My last try on interpreting what you want to do.
$goodEsx = '???'
$newDS = '???'
Get-VMHost -Name $problemEsx | Get-VM |
Move-VM -Destination $goodEsx -Confirm:$false |
Move-VM -Datastore $newDS -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi not quit. We will not be doing it in an all vm approach we have a list and would like it as a check so would be more like this
1 is vm hosted on problem host
yes- move to another host
then storage move
no- vm is on a good host storage move
if we took the approach to move all of the host we could simplify that and place the host into maintenance mode, but we don’t have the capacity to loose a host at this point.
thanks in advance
Jim
Try like this.
The names of the VMs are in the .txt file, one name per line.
$goodEsx = '???'
$newDS = '???'
Get-VM -Name (Get-Content -Path '.\vmnames.txt') -PipelineVariable vm |
ForEach-Object -Process {
if($problemEsx -contains $vm.VMHost.Name){
$vm = Move-VM -VM $vm -Destination $goodEsx -Confirm:$false
}
Move-VM -VM $vm -Datastore $newDS -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great thanks I’ll give it a go today
another approach we are thinking of, if the VM resides on aproblem vm, leave it where it is and move on to the next vm in the text file list. how can i just move on.
Thanks
Jim
Something like this?
$newDS = '???'
Get-VM -Name (Get-Content -Path '.\vmnames.txt') -PipelineVariable vm |
ForEach-Object -Process {
if($problemEsx -notcontains $vm.VMHost.Name){
Move-VM -VM $vm -Datastore $newDS -Confirm:$false
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
brill thanks
That did what i required it to do. thanks for your help, much appreciated