From 8a67dd27d14b8655484c5c967475b1de5f562688 Mon Sep 17 00:00:00 2001 From: onerstam <75037984+onerstam@users.noreply.github.com> Date: Fri, 27 Aug 2021 18:52:54 +0200 Subject: [PATCH] Remove break on warnings in Get-MSIntuneAuthToken Break statements can cause callers to exit execution when placed outside of a loop, switch, or trap. Resolves issue #32 --- Modules/PSIntuneAuth/PSIntuneAuth.psm1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Modules/PSIntuneAuth/PSIntuneAuth.psm1 b/Modules/PSIntuneAuth/PSIntuneAuth.psm1 index 9de39c6..744942c 100644 --- a/Modules/PSIntuneAuth/PSIntuneAuth.psm1 +++ b/Modules/PSIntuneAuth/PSIntuneAuth.psm1 @@ -44,7 +44,7 @@ function Get-MSIntuneAuthToken { Author: Nickolaj Andersen Contact: @NickolajA Created: 2017-09-27 - Updated: 2021-01-12 + Updated: 2021-08-27 Version history: 1.0.0 - (2017-09-27) Function created @@ -59,6 +59,7 @@ function Get-MSIntuneAuthToken { 1.2.1 - (2020-01-15) Fixed an issue where when multiple versions of the AzureAD module installed would cause an error attempting in re-installing the Azure AD module 1.2.2 - (2020-01-28) Added more verbose logging output for further troubleshooting in case an auth token is not aquired 1.2.3 - (2021-01-12) Added support for installing the AzureAD module along side with the AzureADPreview module + 1.2.4 - (2021-08-27) Removed breaks on warnings and return of $null, issue #32 #> [CmdletBinding()] param( @@ -241,27 +242,33 @@ function Get-MSIntuneAuthToken { return $Authentication } else { - Write-Warning -Message "Failure to acquire access token. Response with access token was null"; + Write-Warning -Message "Failure to acquire access token. Response with access token was null" + return $null } } catch [System.Exception] { Write-Warning -Message "An error occurred when attempting to call AcquireTokenAsync method. Error message: $($_.Exception.Message)"; + return $null } } catch [System.Exception] { Write-Warning -Message "An error occurred when constructing an authentication token. Error message: $($_.Exception.Message)"; + return $null } } catch [System.Exception] { Write-Warning -Message "Unable to load required assemblies from AzureAD module to construct an authentication token. Error message: $($_.Exception.Message)"; + return $null } } else { Write-Warning -Message "Azure AD PowerShell module is not present on this system, please install before you continue"; + return $null } } catch [System.Exception] { Write-Warning -Message "Unable to load required AzureAD module to for retrieving an authentication token. Error message: $($_.Exception.Message)"; + return $null } } }