Get-Mailbox progress bar RRS feed

  • Question

  • I'm trying to devise a script while connected to O365 for a large amount of mailboxes. However, Id like to see a progress bar while the script is gathering information. Here is an example of what I have now:

    $Credentials = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri (servername) $Credentials -Authentication Basic
    Import-PSSession $Session -allowclobber
    Write-Host 'Getting Mailbox information, please wait' -ForegroundColor Green
    $mailboxes = Get-mailbox -verbose -resultsize unlimited
    $report = $mailboxes | select name | export-csv ("Mailboxes_" + (get-date).ToShortDateString().Replace("/","-") + ".csv")
    Write-Host "Script has completed, please review the CSV file for more information" -foregroundcolor Green
    Get-PSSession | Remove-PSSession

    • Moved by Bill_Stewart Wednesday, September 4, 2019 6:53 PM Abandoned
    Tuesday, March 19, 2019 8:28 PM

All replies

  • Not all commands allow a progress bar.  Until the command completes you can not execute any code.  You can run the command as a job and display some kind of progress while waiting  for the job to complete.

    Create the job and poll the job in a loop delaying to 1 second and display the elapsed time as a progress bar r as text until the job completes.

    With Get-Mailbox the pipeline can also be a polling loop.

    Get-mailbox -verbose -resultsize unlimited |
            Write-Progress < time or other output >
        } | 
        Select-Object name | 
        export-csv ("Mailboxes_" + (get-date).ToShortDateString().Replace("/", "-") + ".csv") 


    Tuesday, March 19, 2019 8:53 PM
  • so get-mailbox -asjob ?

    How would I display the progress of the job in the loop?

    Tuesday, March 19, 2019 8:58 PM