Hi,
I’m using the Write-Progress cmdlet to show a progress bar for each distribution group processed in a script.
The problem is that it isn’t closing after it reaches 100%.
The only solution someone gave, searching over Bing, it was to use this in the end of the code:
Write-Progress "Done" "Done" -Completed | Out-Default"
Write-Host "Retrieving every distribution groups from Exchange Online..." -ForegroundColor Yellow | Out-Default
Write-Host
$DGs = Invoke-Command -Session (Get-Pssession) -Scriptblock {Get-DistributionGroup | Select-Object -Property DisplayName}
$DGs = $DGs | sort DisplayName
Write-Host "Retrieving members of" $DGs.Count "distribution groups..." -ForegroundColor Yellow | Out-Default
Write-Host
$i = 1
foreach ($DG in $DGs){
Write-Progress -activity “Retrieving members...” -status “Status: ” -PercentComplete (($i / $DGs.count)*100) | Out-Default
$i++
New-Variable $DG -Value (Get-DistributionGroupMember -Identity $DG.DisplayName)
}
Write-Progress "Done" "Done" -Completed | Out-Default
Clear-Host
We have 126 distribution lists on our organization.
Any idea why my progress bar isn’t ending?
PS: The “Out-Default” code part is because the screen wasn’t clearing in my powershell console after showing the progress bar.
Read that tip on: Clearing the screen in PowerShell: A story of blank spaces – Konstantinos Gkoutzis