Progress Bar

Welcome Forums General PowerShell Q&A Progress Bar

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #69459

    Points: 42
    Rank: Member

    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

    Points: 364
    Helping Hand
    Rank: Contributor

    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

    Points: 42
    Rank: Member

    Thanks think i have got this now 🙂

  • #69477

    Points: 0
    Rank: Member

    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)

The topic ‘Progress Bar’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort