Im looking to svMotion VM's based on a spreadsheet or txt file (either will work for me) from one datastore to another. I've found simple ones that do it, but nothing that will import a csv file or txt file and svmotion those VM's.
It might be that the Where-clause in the function is not catching the running vMotions.
When they are running, what does this return ?
(Get-Task | Where{ ($_.PercentComplete -ne 100) -and ( ($_.Description -like '*DRS*') -or ($_.Description -like '*vMotion*') )} | Measure-Object).Count
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It returns 0
That is the reason why the function doesn't work.
The object returned by Get-Task has changed over the different PowerCLI builds.
If you do a (again while there are some vMotion running)
Get-Task | Select -First 1 -Property *
what is returned ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ServerId | : /VIServer=domain\user@vcentername:443/ |
State | : Running |
IsCancelable | : True |
PercentComplete : 5
StartTime | : 10/23/2014 11:42:51 AM |
FinishTime | : |
ObjectId | : VirtualMachine-vm-99187 |
Result | : |
Description | : Relocate virtual machine |
ExtensionData : VMware.Vim.Task
Id | : Task-task-1059314 |
Name | : RelocateVM_Task |
Uid | : /VIServer=domain\user@vcentername:443/Task=Task-task-1059314/ |
Try changing line 37 (in the original function) into this
$NumvMotionTasks = (Get-Task | ? { ($_.PercentComplete -ne 100) -and ($_.Description -match 'Relocate')} | Measure-Object).Count
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What about like 39? Change it to the same thing?
Yes, of course I forgot.
Change the Where-clause on line 42 as well
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My line #'s were off due to adding some other commands, but I picked up what you were laying down. It works like a champ Thanks LucD, ZSoldier, and brentcochran1 for the help.
To get this to go to a Storage Datacluster I changed:
$ds = get-datastore $row.destds
To:
$ds = get-datastorecluster $row.destds
It doesnt seem to be queuing up the storage vMotions now, where as it did when I pointed it directly at the Datastore and not a Datastore cluster. Make sense?
Do you mean the svMotions are now executed in sequence, not in parallel ?
Or is none of the svMotions taking place ?
In the latter case, could it be that SDRS made some recommendations, and is now waiting for which rule you want to approve ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When I ran it with just the individual datastore and not the datastore cluster, it will svmotion no more than 4 at a time. When ran against the datastore cluster the all start sVMotioning at the same time.
Could the different behavior be explained by the fact that the svMotions are going to different datastores ?
While before you had a higher number of svMotions going to the same datastore.
See Limits on Simultaneous Migrations in the vSphere Web Client
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah, potentially.
I just know it ran 25 svMotions at the same time. Is there a way to queue up a number even though its going to a datastore cluster?
Could also be that the $NumvMotionTasks value is not correct.
Put some Write-Verbose lines in the script to display the value each time it enters the loop.
Should give you an idea what value the script calculates
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's whats in the script:
$NumvMotionTasks = (Get-Task | ? { ($_.PercentComplete -ne 100) -and ($_.Description -match 'Relocate')} | Measure-Object).Count
}
Write-Verbose "$(Get-Date)- Proceeding."
The output when I run it shows what it typically would when migrating a VM via script.
Could you perhaps attach the script you are currently using to the thread.
There have been several updates, so I don't know exactly what you are running anymore.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Connect-VIServer vsphereqa
function Wait-mTaskvMotions {
[CmdletBinding()]
Param(
[int] $vMotionLimit=1,
[int] $DelayMinutes=5
)
$NumvMotionTasks = (Get-Task | ? { ($_.PercentComplete -ne 100) -and ($_.Description -match 'Relocate')} | Measure-Object).Count
While ( $NumvMotionTasks -ge $vMotionLimit ) {
Write-Verbose "$(Get-Date)- Waiting $($DelayMinutes) minute(s) before checking again."
Start-Sleep ($DelayMinutes * 60)
$NumvMotionTasks = (Get-Task | ? { ($_.PercentComplete -ne 100) -and ($_.Description -match 'Relocate')} | Measure-Object).Count
}
Write-Verbose "$(Get-Date)- Proceeding."
} # end function
$filepath = "H:\VM Scripts\test_svmotion.csv"
$csvobj = import-csv $filepath
foreach ($row in $csvobj) {
$vmobj = get-vm $row.vmname
$ds = get-datastorecluster $row.destds
$vmobj | move-vm -datastore $ds -confirm:$false -runasync
Wait-mTaskvMotions -vMotionLimit 4 # This will keep going through the foreach loop until 4 tasks are registered (vMotion or Storage vMotion), waits 5 minutes between checks. Will only continue to process loop when vMotion tasks are less than 4.
}
I guess that you run this against a vSphere 5.* environment ?
If yes, the Description property has a different content.
Try like this, I changed the target on the -match operator.
If this doesn't work, check what is actually in the Description property for a vMotion and a svMotion task
Connect-VIServer vsphereqa
function Wait-mTaskvMotions {
[CmdletBinding()]
Param(
[int] $vMotionLimit=1,
[int] $DelayMinutes=5
)
$NumvMotionTasks = (Get-Task | ? { ($_.PercentComplete -ne 100) -and ($_.Description -match 'Apply Storage DRS recommendations|Migrate virtual machine')} | Measure-Object).Count
While ( $NumvMotionTasks -ge $vMotionLimit ) {
Write-Verbose "$(Get-Date)- Waiting $($DelayMinutes) minute(s) before checking again."
Start-Sleep ($DelayMinutes * 60)
$NumvMotionTasks = (Get-Task | ? { ($_.PercentComplete -ne 100) -and ($_.Description -match 'Apply Storage DRS recommendations|Migrate virtual machine')} | Measure-Object).Count
}
Write-Verbose "$(Get-Date)- Proceeding."
} # end function
$filepath = "H:\VM Scripts\test_svmotion.csv"
$csvobj = import-csv $filepath
foreach ($row in $csvobj) {
$vmobj = get-vm $row.vmname
$ds = get-datastorecluster $row.destds
$vmobj | move-vm -datastore $ds -confirm:$false -runasync
Wait-mTaskvMotions -vMotionLimit 4 # This will keep going through the foreach loop until 4 tasks are registered (vMotion or Storage vMotion), waits 5 minutes between checks. Will only continue to process loop when vMotion tasks are less than 4.
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc, i want to capture svmotion start and end time or creating a separate log file is also fine. Any idea how to do that?
I will add that to the Brent's script.
Thanks
I suspect you would need to fetch the task objects for that.
Something like I did in Events – Part 8 – vMotion history
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference