Hi,
I am trying to migrate VMs from one Datastore to another using below command, when I issue this command, all the VMs are migrating at once, I would like to migrate one VM at a time, How can I do it ?
Please help!!!
get-datastore Datastore1 | get-vm | move-vm -Datastore Datastore2
Below are the PowerCLI version installed
PowerCLI Version
----------------
VMware PowerCLI 11.2.0 build 12483598
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 11.2 build 12483642
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.2 build 12483638
You are using the incorrect parameters.
PercentComplete expects an [int], you can pass your text in Status.
Like this
ForEach-Object -Process {
$task = Move-VM -VM $vm -Datastore Datastore2 -RunAsync
while ($task.PercentComplete -ne 100)
{
sleep 5
$task = Get-Task -Id $task.Id
$sProg = @{
Activity = "Storage vMotion"
Status = "$($task.PercentComplete)%"
PercentComplete = ([int]($task.PercentComplete))
}
Write-Progress @sProg
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could run the svMotion as a background task, and then wait till it is completed, before starting the next one.
ForEach-Object -Process {
$task = Move-VM -VM $vm -Datastore Datastore2 -RunAsync
while ($task.PercentComplete -ne 100)
{
sleep 5
$task = Get-Task -Id $task.Id
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for your help.
That worked. Just wanted to know, when do we use -RunAsync parameter ?
The RunAsync switch starts the task corresponding with the cmdlet in the background.
The cmdlet returns immediately without waiting for the background task to complete.
With the Task object, that is returned when using RunAsync, and Get-Task you can monitor the state of the Task.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Got it,
But in the script, does the below line has anything to do ? because,I dont see any task status in the screen ?
$task = Get-Task -Id $task.Id
We have the Task object in that variable, but such an object does not refresh automatically.
That is why we have to refresh the content of the object, to get the actual status
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, how do I refresh to get the actual status ? sorry to bother you.
I use the Id with the Get-Task cmdlet to get the current content of the Task object.
That also includes the property that shows what percentage of the task is completed.
At 100% we continue with the next svMotion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, if I misunderstood this....just wanted to know, if there is a way to display the percentage status in the CLI regarding the task ?
Yes, after the Get-Task -Id $task.Id, the actual percentage is available in the PercentComplete property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I added the below line
Get-Datastore Datastore1 | Get-VM -PipelineVariable vm |
ForEach-Object -Process {
$task = Move-VM -VM $vm -Datastore Datastore2 -RunAsync
while ($task.PercentComplete -ne 100)
{
sleep 5
$task = Get-Task -Id $task.Id
Write-Progress -Activity "Storage vMotion :" -PercentComplete "$($task.PercentComplete)%"
}
}
From the output, number percentage is missing
Output :
You are using the incorrect parameters.
PercentComplete expects an [int], you can pass your text in Status.
Like this
ForEach-Object -Process {
$task = Move-VM -VM $vm -Datastore Datastore2 -RunAsync
while ($task.PercentComplete -ne 100)
{
sleep 5
$task = Get-Task -Id $task.Id
$sProg = @{
Activity = "Storage vMotion"
Status = "$($task.PercentComplete)%"
PercentComplete = ([int]($task.PercentComplete))
}
Write-Progress @sProg
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect....enjoying.....new learning everyday because of you...thank you very much