Get-MsOGroups
MSOnline: Get groups from Azure AD
#Requires -Version 5.1
[CmdletBinding()]
Param(
[switch]$IsAgentRole,
[switch]$HasLicenseErrorsOnly,
[switch]$HasErrorsOnly,
[ValidateSet('All','Security','MailEnabledSecurity','DistributionList')]
[string]$GroupType = 'All',
[guid]$TenantId
)
Process {
try {
[hashtable]$getArgs = @{'ErrorAction' = 'Stop'; 'TenantId' = $TenantId}
if ($IsAgentRole) { $getArgs.Add('IsAgentRole', $true) }
if ($HasLicenseErrorsOnly) { $getArgs.Add('HasLicenseErrorsOnly', $true) }
if ($HasErrorsOnly) { $getArgs.Add('HasErrorsOnly', $true) }
$result = Get-MsolGroup @getArgs -GroupType $GroupType | Select-Object *
if ($null -eq $result -or $result.Count -eq 0) { Write-Output "No groups found"; return }
foreach ($item in $result) { $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') -PassThru -Force }
}
catch { throw }
}Off
Only agent groups (partner users only)
Off
Only security groups with license errors
Off
Only groups with validation errors
Type of groups to retrieve
Unique ID of the tenant