Progress Bar

This topic contains 3 replies, has 3 voices, and was last updated by  Wilfredo Perez 5 months, 3 weeks ago.

  • Author
    Posts
  • #69459

    Mark Prior
    Participant

    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

  • #69469

    Fredrik Kacsmarck
    Participant

    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
    Participant

    Thanks think i have got this now 🙂

  • #69477

    Wilfredo Perez
    Participant

    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)
    }
    
    

You must be logged in to reply to this topic.