Hello
To display the last login date when a user logs in, you can use the Azure Active Directory (Azure AD) sign-in logs and PowerShell. Here’s a step-by-step guide:
Install the Azure AD PowerShell Module: You’ll need to download the Azure AD (or Azure AD Preview) module.
Import the Azure AD Module
Import-Module AzureADPreview
Connect to Azure AD: Use your Azure Admin account to connect to Azure AD.
Connect to Azure AD
Connect-AzureAD -AccountId AzureAdmin@yourdomain.com
Get the Last Login Date: Use the Get-AzureADAuditSignInLogs cmdlet to get the last login date.
Get-AzureADAuditSignInLogs -Filter "UserPrincipalName eq 'username@yourdomain.com'" -Top 1 | `
select CreatedDateTime, UserPrincipalName, IsInteractive, AppDisplayName, IpAddress, TokenIssuerType, @{Name = 'DeviceOS'; Expression = {$_.DeviceDetail.OperatingSystem}}
Replace 'username@yourdomain.com' with the user’s User Principal Name (UPN). This script will return the last login date and other details for the specified user.
Display the Last Login Date: To display the last login date as a banner when a user logs in, you’ll need to incorporate this script into your login script or Group Policy. Please note that this would require additional scripting and testing to ensure it works as expected in your environment.
Remember to replace 'AzureAdmin@yourdomain.com' and 'username@yourdomain.com' with your actual Azure Admin account and the user’s UPN, respectively.
This solution requires administrative access to Azure AD and knowledge of PowerShell. Always test scripts in a controlled environment before deploying them in a production environment. If you’re not comfortable with PowerShell, you may want to consider seeking assistance from someone who is.
Also, please be aware that pulling sign-in logs from Azure AD could have implications for privacy and compliance depending on your organization’s policies and the jurisdiction in which you operate. Always ensure you have appropriate permissions and legal clearance before accessing and displaying user login information.