Progress Bar

trying to wrap my head around these still, as a quick reference where would i put the code to display a progress bar for the below

$users = get-aduser -LDAPFilter "(name=*guest*)" -Properties canonicalname | Select-Object name, Canonicalname

TIA

If you’re talking about Write-Progress then you wouldn’t.
You need to “manually” trigger Write-Progress.

So if you e.g. want to process the users in a foreach or similar you could do.

foreach($u in $users)
{
   $percent = $users.indexOf($u) / $users.length * 100
   Write-Progress -Activity "Processing users" -Status "$percent% Complete" -PrecentComplete $percent
}

But as Get-ADUser will be processed inside the cmdlet you don’t really have that option and the select is just a filter on what to pull from the output of Get-ADUser.

But maybe you’re talking about a different progress bar?

Thanks think i have got this now :slight_smile:

Try this

$i = 0
$adUser = (Get-ADUser -Filter *).name
foreach($user in $adUser){
$i++
Write-Host $user
Write-Progress -Activity "Getting AD Users..." -Status "Status:" -PercentComplete (($i/$adUser.Count)*100)
}