Calling @odata.nextlink from powershell

Viewed 2127

I'm trying to figure out how to call the odata.nextlink from a powershell script im writing to get Azure AD signin information for users.

$LastLogin = Invoke-WebRequest -Headers $AuthHeader1 -Uri "https://graph.microsoft.com/beta/users?`$select=displayName,userPrincipalName,signInActivity" -Verbose
$result = ($LastLogin.Content | ConvertFrom-Json).Value
$result  | select DisplayName,UserPrincipalName,@{n="LastLoginDate";e={$_.signInActivity.lastSignInDateTime}}

and it results in the first 100 results being disaplayed

if I view the $lastLogin output I can see the content includes the odata.nextlink option but I can't seem to get the uri to pass into a while loop to get all the results

$lastLogin output image

if I do $lastLogin."@odata.nextLink' it just returns a null value.

Where am I going wrong?

Thanks

1 Answers

In the second step rather using the

$result = ($LastLogin.Content | ConvertFrom-Json).Value

Use $result = ($LastLogin.Content | ConvertFrom-Json) and then pull the nextLink using the $result.'@odata.nextLink'

It worked for me.

enter image description here

Related