Progress Bars

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Mark Prior Mark Prior 6 months, 2 weeks ago.

  • Author
    Posts
  • #61606
    Profile photo of Mark Prior
    Mark Prior
    Participant

    Hi Gents

    so i have a small script (not finished yet) to create some room mailboxes (approx 600) i would like to add a progress bar to show how far the script is along in % (for the creation of the MB, then the remaining sleep time). something im struggling with is applying the examples around to my own situation, im sure once i see it in action with my own process everything will click.

    
    ###Set Variables###
    
    $data = Import-Csv "H:\EMEA Messaging\Meeting Rooms\test Data.csv"
    $ou = "contoso.com/Move-Objects/SG-Test"
    $PWD = "MeetingRoom01"
    
    ## Only set while exchange is spread across DBs##
    $DB = "EU_DAG1_db3"
    
    ###Create Meeting Rooms###
    
    $data | ForEach-Object {
    
    New-Mailbox -Name $_.displayname -Alias $_.alias -UserPrincipalName $_.upn -Org $ou -Password (ConvertTo-SecureString $PWD -AsPlainText -Force) -Database $DB -room
    
    }
    
    ###Hides Rooms from Address Book###
    
    
    Sleep -Seconds 90 -Verbose
    
    Get-mailbox -OrganizationalUnit $OU | Set-Mailbox -HiddenFromAddressListsEnabled $TRUE
    
    ##Set-Calendarprocessing CDMlets for resourcing options####
    
    
    

    TIA

  • #61609
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    something like this ?

    $data = 1..100 # demo data
    $data | ForEach-Object -Begin {
      $i=0
    } -Process {
      $i++
      Write-Progress -Activity "Activity around $_" -Status "Invoking ..." -PercentComplete ($i/$data.Count*100)
      start-sleep -Seconds 1
    }
    
  • #61641
    Profile photo of Mark Prior
    Mark Prior
    Participant

    hi max im still unsure how to integrate this to the script ?

  • #61683
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    place it here and modify messages to your needs

    # [...] your code
    $i=0
    $data | ForEach-Object {
    # progress bar addition start
    $i++
    Write-Progress -Activity "Activity around $_" -Status "Invoking ..." -PercentComplete ($i/$data.Count*100)
    # progress bar addition end
    
    New-Mailbox -Name $_.displayname -Alias $_.alias -UserPrincipalName $_.upn -Org $ou -Password (ConvertTo-SecureString $PWD -AsPlainText -Force) -Database $DB -room
    
    }
    # [...] your code
    
  • #61690
    Profile photo of Mark Prior
    Mark Prior
    Participant

    Thanks Max, Think i have gotten in my head how this works now

You must be logged in to reply to this topic.