Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created October 5, 2018 10:07
Show Gist options
  • Save OlafD/4384edf8d31bdce945742087f8ef5dd7 to your computer and use it in GitHub Desktop.
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.
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