Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active March 31, 2024 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/9b3eeaf5c90c89cb6bb9733a7932df52 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/9b3eeaf5c90c89cb6bb9733a7932df52 to your computer and use it in GitHub Desktop.
Get completion percentage for batch VM clone tasks
# 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)
}
@AfroThundr3007730
Copy link
Author

Updated version available in my HelperFunctions module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment