Advertisement
shadmorris

Untitled

Jun 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function ProgressBar
  2. {Param([double]$i,[string]$status)
  3.     write-progress -activity "Converting DisplayNames to PrimarySMTPAddresses..." -status $status -percentcomplete $i
  4. }
  5.  
  6. ########CONSTANTS
  7. $FILELOCATION = "Path to CSV File"
  8. ########
  9.  
  10. ########MAIN
  11. $groups = import-csv $FILELOCATION
  12.  
  13. #Create increment for progress bar completion rate.
  14. $count = 100 / ($groups).count
  15. $x=0
  16.  
  17. #Connect to Exchange Online.
  18. $pass = cat c:\users\shmorris\securestring.txt | convertto-securestring
  19. $mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "<CREDUPN>",$pass
  20. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential $mycred -Authentication Basic –AllowRedirection
  21. Import-PSSession $Session
  22.  
  23. foreach ($group in $groups)
  24. {
  25.     $managedByArray = @()
  26.     $ownerString = $null
  27.     try
  28.     {
  29.         $managedByArray = (Get-UnifiedGroupLinks $group.alias -linktype Owner).primarysmtpaddress
  30.         foreach ($owner in $managedByArray)
  31.         {
  32.             $ownerString = $ownerString + $owner + ";"
  33.         }
  34.     }
  35.     Catch
  36.     {
  37.         $managedByArray = $null
  38.     }
  39.  
  40.     $group.Alias+","+$group.PrimarySMTPAddress+","+$group.DisplayName+","+$group.ExternalDirectoryObjectId+","+$group.WhenCreatedUTC+","+$group.ManagedBy+","+$recipientList >> GroupOutput.csv
  41.  
  42.     $x = $x + $count
  43.     ProgressBar $x $group.Alias
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement