Get-MsOUsers
MSOnline: Get users from Azure AD
#Requires -Version 5.1
[CmdletBinding()]
Param(
[switch]$HasErrorsOnly,
[switch]$OnlyDeletedUsers,
[switch]$OnlyUnlicensedUsers,
[switch]$LicenseReconciliationNeededOnly,
[ValidateSet('All','EnabledOnly','DisabledOnly')]
[string]$Filter = 'All',
[guid]$TenantId
)
Process {
try {
[hashtable]$getArgs = @{'ErrorAction' = 'Stop'; 'TenantId' = $TenantId}
if ($HasErrorsOnly) { $getArgs.Add('HasErrorsOnly', $true) }
if ($OnlyDeletedUsers) { $getArgs.Add('ReturnDeletedUsers', $true) }
if ($OnlyUnlicensedUsers) { $getArgs.Add('UnlicensedUsersOnly', $true) }
if ($LicenseReconciliationNeededOnly) { $getArgs.Add('LicenseReconciliationNeededOnly', $true) }
if ($Filter -ne 'All') { $getArgs.Add('EnabledFilter', $Filter) }
$result = Get-MsolUser @getArgs | Select-Object *
if ($null -eq $result -or $result.Count -eq 0) { Write-Output "No users 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 users with validation errors
Off
Only users in recycle bin
Off
Only users without a license
Off
Only users needing license reconciliation
Filter by enablement status
Unique ID of the tenant