Created
March 19, 2020 20:55
-
-
Save nicolonsky/798cfc9c0b5543647347cf09de6ef3c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check Azure AD Access token | |
if ($null -eq [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens){ | |
Connect-AzureAD | |
} else { | |
$token = [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens | |
Write-Verbose "Connected to tenant: $($token.AccessToken.TenantId) with user: $($token.AccessToken.UserId)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It didn't always worked for me, I had to add a check for an empty token:$token.AccessToken.TenantId) with user: $ ($token.AccessToken.UserId)"
$token = [Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens
if (($null -eq $token) -or ($token.count -eq 0)){
Connect-AzureAD
} else {
Write-Verbose "Connected to AzureAD tenant: $(
}