Hi all, does anyone have any power cli sample to retrieve the status of vm cloning without the need to access thru the vSphere Client ?
Why not just...
get-task | ?{$_.name -like "CloneVm_Task"}
Afaik that is not possible.
You could look at the events of the target host and filter out the events related to the creation of the new VM, but that will not give you the status of the cloning task.
Out of curiousity, how do you start the cloning process without a connection to the vCenter Server ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I actually make use of the web service SDK thru my web to pass in the parameters to connect to the vCenter Server for the cloning so that i do not require to install vSphere Client on different pc.
Can't you access the TaskManager in a similar way and interrogate the recentTask property ?
That is in fact what the Get-Task cmdlet is doing.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there any sample code for it?
Why not just...
get-task | ?{$_.name -like "CloneVm_Task"}
Hi CRad14,
Thanks very much for your help. I'm able to get the cloning status for the VM now.
Seems like i have alot more to learn on the powercli script.
My pleasure! Have a good one!!
So to take this further, I'd like to monitor a running task that could take over 5hrs. Currently this provides a percentage complete:
Get-Task | ? {$_.Description -eq "Relocate virtual machine" -and $_.State -eq "Running"} | ft -a
Could someone expand to make some type of "while" loop or once task hits 99 or 100%, then send an email?
Try something like this
Get-Task | where {$_.Description -eq "Relocate virtual machine" -and "Running","Success" -contains $_.State -and $_.PercentComplete -ge 70} | %{ Send-MailMessage -SmtpServer mailserver.domain -Subject "Job $($_.Id) at $($_.PercentComplete) percent" -To me@domain -From me@domain
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yea, that's great Luc! Now can you advise how to make this one-liner actively sit and monitor the progress then send email once it hits 98% complete or equals success? Something like "do, while"?
Hmm, getting closer to what I want, but now I need to either use Wait-task or some type of sleep timer? Ideas please??
Get-Task | ? {$_.Description -eq "Relocate virtual machine"}; do {Get-Task | ? {$_.Description -eq "Relocate virtual machine" -and $_.State -eq "Running"}} until ($_.State -eq "success")
Produces:
OK, this is working and providing status back to the screen every 5mins. Still not precisely what I need, I need a way to generate email when completed.
Can I simply add this to the end of my line below?
| %{Send-MailMessage -SmtpServer mailserver.domain -Subject "Job $($_.Id) at $($_.PercentComplete) ` percent" -To me@domain -From me@domain
Get-Task | ? {$_.Description -eq "Relocate virtual machine"}; do {Get-Task | ? {$_.Description -eq "Relocate virtual machine" -and $_.State -eq "Running"}} until (start-sleep -seconds 600) ($_.State -eq "success")
Would this do the trick ?
$tasks = Get-Task | where {$_.Description -eq "Relocate virtual machine"} while($tasks){ sleep 5 $tasks = Get-Task | where {$_.Description -eq "Relocate virtual machine" -and $_.State -eq "Running"} } Get-Task | where {$_.Description -eq "Relocate virtual machine" -and "Success","Error" -contains $_.State} | %{ Send-MailMessage -SmtpServer mailserver.domain -Subject "Job $($_.Id) at complete, status $($_.State)" -To me@domain -From me@domain
}
In the loop the script waits for 5 seconds before fetching the tasks again.
The loop continues till all tasks are either completed or in error.
Then it sends an email per task that was completed or errored out.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi tayky & CRad14,
Even Iam Looking For solution of the same Problem( Knowing the Status(%) of VM Clone ),and thanks for your answer (CRad14) ,but here i have one Question,
Iam Creating Multiple VMs from Template using the Powercli with -RunAsync Parameter,then how can i differentiate the CloneVM_Task ,i.e which task represents the status of which VM ?..
Iam using New-VM Command let to create a new VM using the Template and One OSCustomizationSpec file (Unattended File) which is already Created.
but if different users are connected from different places to VCenter and created VMs then how can i diferentiate the Which Task Status indicates the Which VM creationbecause all the tasks are Having Same Name "VMClone_Task"
Thanks In Advance