Check if AzureAD connection has been established in Powershell
When scripting, you might need to check if you AzureAD connection is active before doing anything.
Solution
try {
$var = Get-AzureADTenantDetail
}
catch [Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthenticationException] {
Write-Host "You're not connected to AzureAD";
Write-Host "Make sure you have AzureAD mudule available on this system then use Connect-AzureAD to establish connection";
exit;
}
Source
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.