Skip to content

Instantly share code, notes, and snippets.

@merill
Last active November 29, 2021 17:56
Show Gist options
  • Save merill/2238812c8007601b5c1b36b2e7cb8b7e to your computer and use it in GitHub Desktop.
Save merill/2238812c8007601b5c1b36b2e7cb8b7e to your computer and use it in GitHub Desktop.
Install-Module Microsoft.Graph
Import-Module Microsoft.Graph
Connect-MgGraph
Select-MgProfile -Name beta
Get-MgUser -All -Filter "userType eq 'Guest'" -Select "mail,userPrincipalName,signInActivity" | Select-Object -Property mail,@{Name = 'LastSignIn'; Expression = {$_.signInActivity.lastSignInDateTime}}
@andypturner
Copy link

Hi @merill, thanks for getting back to me. There was no error, just an absence of data for that property.

I'm new to the graph module so didn't look at the syntax, especially since it wasn't giving an error. But I've managed to make it work now. I wonder has something changed in the module as -Select doesn't appear to be a parameter of Get-MgUser (docs).

The following works (even without the scope):

Connect-MgGraph -Scopes "User.Read"
Select-MgProfile -Name beta
Get-MgUser -All -Filter "userType eq 'Guest'" -Property signInActivity | Select-Object -Property mail,@{Name = 'LastSignIn'; Expression = {$_.signInActivity.lastSignInDateTime}}

It's interesting because I couldn't get signInActivity to return using the Graph Explorer unless I consented to AuditLog.Read.All (and maybe some of the others). I might have to revisit that and see if that's really true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment