Created
October 5, 2018 10:07
-
-
Save OlafD/4384edf8d31bdce945742087f8ef5dd7 to your computer and use it in GitHub Desktop.
Get all the assigned owners of an Office 365 Groups group, also getting the owners in a Teams team. The script connects to Exchange Online to get the information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$GroupName, | |
$Credentials | |
) | |
if ($Credentials -eq $null) | |
{ | |
$Credentials = Get-Credential | |
} | |
Write-Host "Connecting to Exchange Online" | |
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credentials -Authentication Basic -AllowRedirection | |
Import-PSSession $exchangeSession -DisableNameChecking | Out-Null | |
Write-Host "Connected to Exchange Online" | |
$group = Get-UnifiedGroup | Where { $_.DisplayName -eq $GroupName } | |
if ($group -ne $null) | |
{ | |
$groupId = $group.ExternalDirectoryObjectId | |
Get-UnifiedGroupLinks -LinkType Owners -Identity $groupId | ft DisplayName, PrimarySmtpAddress | |
} | |
else | |
{ | |
Write-Host -ForegroundColor Red "The group $GroupName could not be found." | |
} | |
Remove-PSSession $exchangeSession |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment