Files
management-scripts/Connect-MSO365.ps1
T
2020-08-30 23:05:07 -04:00

32 lines
990 B
PowerShell

#Requires -Version 3.0
param([string]$User)
## Install ExchangeOnlineManagement module if it doesn't already exist
If ( !(Get-Module -ListAvailable -Name ExchangeOnlineManagement) )
{
Try { Install-Module -Name ExchangeOnlineManagement -RequiredVersion 1.0.1 }
Catch { Write-Output $_.Exception.Message ; Exit }
}
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName $User -ShowProgress $true
$Groups = Get-UnifiedGroup -ResultSize Unlimited
$Groups | ForEach-Object {
$group = Get-UnifiedGroupLinks -Identity $_.Name -LinkType Members -ResultSize Unlimited
$group | ForEach-Object {
New-Object -TypeName PSObject -Property @{
Group = $group.DisplayName
Member = $_.Name
EmailAddress = $_.PrimarySMTPAddress
RecipientType= $_.RecipientType
}
}
} | Export-CSV ${Env:UserProfile}\Desktop\group-export.csv" -NoTypeInformation -Encoding UTF8
Disconnect-ExchangeOnline