Progress Bar

This topic contains 3 replies, has 3 voices, and was last updated by  Wilfredo Perez 1 year, 1 month ago.

  • Author
  • #69459

    Mark Prior

    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


  • #69469

    Fredrik Kacsmarck

    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?

  • #69474

    Mark Prior

    Thanks think i have got this now 🙂

  • #69477

    Wilfredo Perez

    Try this

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

You must be logged in to reply to this topic.