How to check a user belongs to multiple Azure AD Tenants using Azure PowerShell?
HKPR
41
Reputation points
Can we check the user belongs to multiple tenants using PowerShell.
I have tried for the single user but still getting the issues with the below code:
Install-Module -Name AzureAD
Import-Module -Name AzureAD
# Install-Module -Name Az
$tenantDomain1 = "xxx.onmicrosoft.com"
Connect-AzureAD -TenantDomain $tenantDomain1
$tenant = Get-AzureADTenantDetail
$tenantId = $tenant.ObjectId
Write-Host "Tenant ID: $tenantId"
Connect-AzAccount -Tenant $tenantId
$user = Get-AzureADUser -Filter "DisplayName eq 'Samson'"
if (!$user) {
Write-Host "User not found in the specified tenant"
} else {
Write-Host "User found in the specified tenant"
}
- Could anyone please correct any wrong in above code - that code belongs to checking the user belongs to current tenant.
- how to check the same user belongs to multiple tenants using PowerShell query.
Sign in to answer