Last active
March 31, 2024 18:55
-
-
Save AfroThundr3007730/9b3eeaf5c90c89cb6bb9733a7932df52 to your computer and use it in GitHub Desktop.
Get completion percentage for batch VM clone tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get completion percentage for batch VM clone tasks | |
function Get-VMDeployProgress() { | |
[Alias('deployProgress')] | |
Param( | |
[string]$VCUser = $global:DefaultVIServers[0].User.Split('\')[1] | |
) | |
do { | |
$Tasks = Get-Task | Where-Object { $_.Name -match 'clone' ` | |
-and $_.State -match 'running' ` | |
-and $_.ExtensionData.Info.Reason.UserName -match $VCUser } | |
if ($null -eq $Original) { $Original = $Tasks.Count } | |
$Running = $Percent = 0 | |
foreach ($Task in $Tasks) { | |
$Percent += $Task.PercentComplete | |
if ($Task.state -match 'Running') { $Running++ } | |
} | |
$Total = (($Original - $Running) * 100 + $Percent) / $Original | |
Write-Progress -Activity 'Deploying VMs' -PercentComplete $total ` | |
-Status ('VMs still deploying: {0} of {1}, {2:n}% complete...' ` | |
-f $running, $original, $total) | |
Start-Sleep 1 | |
} | |
while ($Running -ne 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version available in my HelperFunctions module.