Hi,@Glenn Maxwell
Thanks for posting your question in the Microsoft Q&A forum.
- Install the Azure AD PowerShell Module if you haven't already. You can install it using the following command:
Install-Module -Name AzureAD
- Connect to your Azure AD with your admin account using:
Connect-AzureAD
- Import your list of users from the CSV file:
$users = Import-Csv -Path "path_to_your_csv.csv"
- Loop through each user in the CSV and retrieve their last sign-in date:
foreach ($user in $users) { $signInLogs = Get-AzureADAuditSignInLogs -Filter "userPrincipalName eq '$($user.UserPrincipalName)'" -Top 1 | Sort-Object CreatedDateTime -Descending if ($signInLogs) { $lastSignIn = $signInLogs.CreatedDateTime # Output user and last sign-in date Write-Output "$($user.UserPrincipalName) last signed in on $lastSignIn" } else { Write-Output "$($user.UserPrincipalName) has no sign-in logs" } }
Please replace "path_to_your_csv.csv" with the actual path to your CSV file and ensure that your CSV has a column named "UserPrincipalName" for the user's principal name.
If my answer is helpful to you, please mark it as the answer so that other users can refer to it. Thank you for your support and understanding.