MSEndpointMgr / IntuneWin32App

Provides a set of functions to manage all aspects of Win32 apps in Microsoft Intune.
MIT License
343 stars 88 forks source link

Test-AccessToken function has errors when $AccessToken doesn't exist yet #138

Closed That-Annoying-Guy closed 7 months ago

That-Annoying-Guy commented 8 months ago

Steps to reproduce:

Install-Module -Name IntuneWin32App 
Test-AccessToken    

Result:

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.3\Public\Test-AccessToken.ps1:32 char:9
+         $TokenExpireMinutes = [System.Math]::Round(([datetime]$Global ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

False

Cause: $Global:AccessToken doesn't exists because Connect-MSIntuneGraph must be used to create it.

Solution: In Test-AccessToken.ps1, add something like at the top of Process section

        If ($null -eq $Global:AccessToken) {
            return $false
        }
NickolajA commented 7 months ago

Good catch, added in 1.4.4. Thanks!