From 21b0c09691d864f30a00d611f568a6fde10b7afb Mon Sep 17 00:00:00 2001 From: Nickolaj Andersen Date: Thu, 7 Mar 2024 23:58:57 +0100 Subject: [PATCH] 1.4.4 --- Public/Test-AccessToken.ps1 | 30 ++++++++++++++++++------------ ReleaseNotes.md | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Public/Test-AccessToken.ps1 b/Public/Test-AccessToken.ps1 index 39be5b1..374009e 100644 --- a/Public/Test-AccessToken.ps1 +++ b/Public/Test-AccessToken.ps1 @@ -13,11 +13,12 @@ function Test-AccessToken { Author: Nickolaj Andersen Contact: @NickolajA Created: 2021-04-08 - Updated: 2023-09-04 + Updated: 2024-03-07 Version history: 1.0.0 - (2021-04-08) Script created 1.0.1 - (2023-09-04) Updated to use TotalMinutes instead of Minutes property, which would cause for inaccurate results + 1.0.2 - (2024-03-07) Invocation of function when access token is null will now return false #> param( [parameter(Mandatory = $false, HelpMessage = "Specify the renewal threshold for access token age in minutes.")] @@ -25,20 +26,25 @@ function Test-AccessToken { [int]$RenewalThresholdMinutes = 10 ) Process { - # Determine the current time in UTC - $UTCDateTime = (Get-Date).ToUniversalTime() - - # Determine the token expiration count as minutes - $TokenExpireMinutes = [System.Math]::Round(([datetime]$Global:AccessToken.ExpiresOn.ToUniversalTime().UtcDateTime - $UTCDateTime).TotalMinutes) - - # Determine if refresh of access token is required when expiration count is less than or equal to minimum age - if ($TokenExpireMinutes -le $RenewalThresholdMinutes) { - Write-Verbose -Message "Access token refresh is required, current token expires in (minutes): $($TokenExpireMinutes)" + if ($Global:AccessToken -eq $null) { return $false } else { - Write-Verbose -Message "Access token refresh is not required, remaining minutes until expiration: $($TokenExpireMinutes)" - return $true + # Determine the current time in UTC + $UTCDateTime = (Get-Date).ToUniversalTime() + + # Determine the token expiration count as minutes + $TokenExpireMinutes = [System.Math]::Round(([datetime]$Global:AccessToken.ExpiresOn.ToUniversalTime().UtcDateTime - $UTCDateTime).TotalMinutes) + + # Determine if refresh of access token is required when expiration count is less than or equal to minimum age + if ($TokenExpireMinutes -le $RenewalThresholdMinutes) { + Write-Verbose -Message "Access token refresh is required, current token expires in (minutes): $($TokenExpireMinutes)" + return $false + } + else { + Write-Verbose -Message "Access token refresh is not required, remaining minutes until expiration: $($TokenExpireMinutes)" + return $true + } } } } \ No newline at end of file diff --git a/ReleaseNotes.md b/ReleaseNotes.md index e1522a7..5d564fe 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -6,6 +6,8 @@ - Improved (hopefully) all aspects as to add and remove supersedence and dependencies. - Improved return object property handling in `Get-IntuneWin32AppAssignment` function to include the same properties independent if using ID or Group parameter set. GroupID and GroupName properties are now also visible in the return object from the function when the ID parameter set is used and an assignment target type matches a group. - Fixed a typo in the Test-AccessToken inner function of the `New-IntuneWin32AppDependency` function implementation where it was not encapsulating the function execution inside parentheses. +- Merged PR: ValidateRange works not as intended because the values are strings #142 +- Fixed mentioned issue with `Test-AccessToken` function mentioned in #138 ## 1.4.3 - Updated the New-IntuneWin32AppPackage function to work properly after the latest version of the IntuneWinAppUtil.exe was recently updated.