Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function ProgressBar
- {Param([double]$i,[string]$status)
- write-progress -activity "Converting DisplayNames to PrimarySMTPAddresses..." -status $status -percentcomplete $i
- }
- ########CONSTANTS
- $FILELOCATION = "Path to CSV File"
- ########
- ########MAIN
- $groups = import-csv $FILELOCATION
- #Create increment for progress bar completion rate.
- $count = 100 / ($groups).count
- $x=0
- #Connect to Exchange Online.
- $pass = cat c:\users\shmorris\securestring.txt | convertto-securestring
- $mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "<CREDUPN>",$pass
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential $mycred -Authentication Basic –AllowRedirection
- Import-PSSession $Session
- foreach ($group in $groups)
- {
- $managedByArray = @()
- $ownerString = $null
- try
- {
- $managedByArray = (Get-UnifiedGroupLinks $group.alias -linktype Owner).primarysmtpaddress
- foreach ($owner in $managedByArray)
- {
- $ownerString = $ownerString + $owner + ";"
- }
- }
- Catch
- {
- $managedByArray = $null
- }
- $group.Alias+","+$group.PrimarySMTPAddress+","+$group.DisplayName+","+$group.ExternalDirectoryObjectId+","+$group.WhenCreatedUTC+","+$group.ManagedBy+","+$recipientList >> GroupOutput.csv
- $x = $x + $count
- ProgressBar $x $group.Alias
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement