We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The use of a break statement after Write-Warning, when not in a loop, will case also consumers of this commandlet to exit execution. See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_break?view=powershell-7.1 section Do not use break outside of a loop, switch, or trap
break
Write-Warning
loop
switch
trap
Write-Warning -Message "Failure to acquire access token. Response with access token was null"; break
Below is with context in PSIntuneAuth.psm1
# Check if access token was acquired if ($AuthenticationResult.AccessToken -ne $null) { Write-Verbose -Message "Successfully acquired an access token for authentication" # Construct authentication hash table for holding access token and header information $Authentication = @{ "Content-Type" = "application/json" "Authorization" = -join("Bearer ", $AuthenticationResult.AccessToken) "ExpiresOn" = $AuthenticationResult.ExpiresOn } # Return the authentication token return $Authentication } else { Write-Warning -Message "Failure to acquire access token. Response with access token was null"; break }
This isssue can be seen using a script like this.
$Tenant = "sometenant.onmicrosoft.com" [securestring]$password = ConvertTo-SecureString "AlwaysWr0ng!" -AsPlainText -Force [pscredential]$credentials = New-Object System.Management.Automation.PSCredential ("[email protected]", $password) Write-Host "Getting the AuthToken ..." $Global:AuthToken = Get-MSIntuneAuthToken -TenantName $Tenant -Credential $credentials Write-Host "This will never be executed ... "
This would be better implemented with this pattern:
else { Write-Warning -Message "Failure to acquire access token. Response with access token was null"; return $null }
The text was updated successfully, but these errors were encountered:
Remove break on warnings in Get-MSIntuneAuthToken
8a67dd2
Break statements can cause callers to exit execution when placed outside of a loop, switch, or trap. Resolves issue MSEndpointMgr#32
No branches or pull requests
The use of a
break
statement afterWrite-Warning
, when not in a loop, will case also consumers of this commandlet to exit execution. See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_break?view=powershell-7.1 section Do not usebreak
outside of aloop
,switch
, ortrap
Below is with context in PSIntuneAuth.psm1
This isssue can be seen using a script like this.
This would be better implemented with this pattern:
The text was updated successfully, but these errors were encountered: