---
title: "Comment by Stevie Lamb on \"Get Intune Compliance data using PowerShell leveraging Graph API\" | Hashnode"
description: "Hi Ondrej, Thanks for you published work, I&#39;ve found it very useful so far. I&#39;ve chosen to use MSAL.PS to acquire a header, alongside a self-signed cert"
url: "https://hashnode.com/posts/get-intune-compliance-data-using-powershell-leveraging-graph-api/60f6969fd6a73079b398bae3/comment/62b072f3c0f84f6b540d1028"
---

[Discussion](https://hashnode.com/posts/get-intune-compliance-data-using-powershell-leveraging-graph-api/60f6969fd6a73079b398bae3)

Comment [Get Intune Compliance data using PowerShell leveraging Graph API](https://hashnode.com/posts/get-intune-compliance-data-using-powershell-leveraging-graph-api/60f6969fd6a73079b398bae3)

[Stevie Lamb](https://hashnode.com/@StevieLamb)

[Jun 20, 2022](https://hashnode.com/posts/get-intune-compliance-data-using-powershell-leveraging-graph-api/60f6969fd6a73079b398bae3/comment/62b072f3c0f84f6b540d1028)

Hi Ondrej,

Thanks for you published work, I've found it very useful so far.

I've chosen to use MSAL.PS to acquire a header, alongside a self-signed certificate, rather than the hard-coded secret.

Regardless of that: many people have environments large enough that their token will expire. Can you suggest a simple method of handling token refresh when calling your functions to avoid such scenarios?

Many thanks,

Stevie

For those interested in using MSAL.PS and certs instead of New-IntuneAuthHeader:

-   generate a self-signed certificate key-pair on your computer
    
-   add its public key to the App Reg you created as documented by Ondrej
    
-   install the MSAL.PS module
    
-   use Get-MsalToken to acquire a token
    

```
# store your thumbprint
$thumbprint = <your certificate's thumbprint> # this is visible in your registered app's Credentials and Secrets section once it has been added

# store the path to your private key based on the thumbprint
$path = "Cert:\CurrentUser\My\" + $thumbprint

# set a hashtable for the connection parameters
$connectionDetails = @{
            'TenantId'          = <your tenant Id>
            'ClientId'          = <your app's client ID>
            'ClientCertificate' = Get-Item -Path $path
        }

$token = Get-MsalToken @connectionDetails

# create an auth header from that token
 $header = @{
            'Authorization' = $token.CreateAuthorizationHeader()
        }
```

you can now use the above `$header` when calling either of Ondrej's awesome functions.

[Ondrej Sebela](https://hashnode.com/@AndrewZtrhgf)

[Jun 23, 2022](https://hashnode.com/posts/get-intune-compliance-data-using-powershell-leveraging-graph-api/60f6969fd6a73079b398bae3/comment/62b072f3c0f84f6b540d1028#reply-62b3faf2b86f939ac81aec15)

Thank you 🙂

According the expired header. I saw solution on the internet where custom new attribute is put into $header variable with time of the token generation. Not sure what the token lifetime is but before you use it, you can then check whether it is valid and if not generate the new one...
