Created
January 25, 2021 14:56
-
-
Save joerodgers/b632d02e5282668fd9fbb868eb78a292 to your computer and use it in GitHub Desktop.
Example using Microsoft Graph PS Module to query signInActivity/lastSignInDateTime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One time installation | |
Install-Module -Name Microsoft.Graph | |
# connect | |
Connect-MgGraph -Scopes "User.Read.All", "AuditLog.Read.All" | |
Select-MgProfile -Name "beta" | |
# will return all users with a date value for lastSignInDateTime | |
$date = [DateTime]::Today.AddDays(-90) | |
$users = Get-MGUser -Filter "signInActivity/lastSignInDateTime le $($date.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ"))" -Select Id, userPrincipalName, mail, onPremisesLastSyncDateTime, onPremisesDistinguishedName, signInActivity | |
$users | SELECT ID, mail, userprincipalname, onPremisesLastSyncDateTime, onPremisesDistinguishedName, @{N="lastSignInDateTime"; e={$_.signInActivity.lastSignInDateTime}} | |
# will return all users with no date value for lastSignInDateTime (has to pull all users, so will be slow) | |
$users = Get-MGUser -Select Id, userPrincipalName, mail, onPremisesLastSyncDateTime, onPremisesDistinguishedName, signInActivity | |
$users | SELECT mail, userPrincipalName, onPremisesLastSyncDateTime, onPremisesDistinguishedName | ? { $_.signInActivity.lastSignInDateTime -eq $null } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment