Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

Secrets and Certificate Expiry with Graph Powershell

$
0
0

So, hope someone can help me across the finish line with this. I've cobbled together a bit of code, basically something I got from a much smarter forum user for a similar purpose.

I'm trying to take all the App Registrations and their secrets/certificate expiry dates and put that information into a PSCustomObject.

This is the bit of code that does the work

# Loop through all apps and add to PSCustomObject$uri = 'https://graph.microsoft.com/beta/applications?$select=displayName, passwordCredentials, id'$result = do {    $Data = Invoke-RestMethod -Method Get -Uri $uri -Headers $Headers    $uri = $Data.'@odata.nextLink'    foreach ($app in $Data.value) {        $appUri = 'https://graph.microsoft.com/beta/applications?$select=displayName, passwordCredentials, id'        $allAppSecretsExpiry = do {            $cred = Invoke-RestMethod -Method Get -Uri $appUri -Headers $Headers            $appUri = $cred.'@odata.nextLink'            if ($cred) {                $cred.value.passwordCredentials.endDateTime            }        }        while ($appUri)        [pscustomobject]@{            displayName = $app.displayName            id          = $app.id            Credentials = $allAppSecretsExpiry        }    }}while ($uri)

Then, what I get is a list of all apps and their ID, but the property for expiration date, I get all expiry dates for all apps, something like this

APP1      {2025-05-15 17:55:57, 2024-08-13 08:55:07, 2026-04-15 09:06:50, 202…APP2      {2025-05-15 17:55:57, 2024-08-13 08:55:07, 2026-04-15 09:06:50, 202…APP3      {2025-05-15 17:55:57, 2024-08-13 08:55:07, 2026-04-15 09:06:50, 202…APP4      {2025-05-15 17:55:57, 2024-08-13 08:55:07, 2026-04-15 09:06:50, 202…

I'm sure I've made a mistake in the foreach loop, but I can't see where.

Hopefully some kind soul can help me out and I'll learn something along the way.


Viewing all articles
Browse latest Browse all 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>