ยท Emad Adel ยท Azure  ยท 2 min read

How to Get a Last Sign-In Report for All Users and Devices in Active Directory

Active Directory (AD) is a critical component for IT administrators to manage users and devices in a network. ๐Ÿš€ One common requirement is to generate reports on the last sign-in activity for users and devices in AD.

Active Directory (AD) is a critical component for IT administrators to manage users and devices in a network. ๐Ÿš€ One common requirement is to generate reports on the last sign-in activity for users and devices in AD.

Active Directory (AD) is a critical component for IT administrators to manage users and devices in a network. ๐Ÿš€ One common requirement is to generate reports on the last sign-in activity for users and devices in AD. ๐Ÿ”„ In this guide, I will show you how to use PowerShell to achieve this efficiently. ๐Ÿ”ง


๐Ÿ“„ Prerequisites

To follow this guide, you need:

  1. ๐Ÿ’ป PowerShell installed on your system (version 5.1 or later).
  2. ๐Ÿ“ Active Directory PowerShell module installed.
  3. ๐Ÿ”’ Appropriate permissions to query Active Directory.

๐Ÿ”ข PowerShell Commands to Get Last Sign-In Reports

1. ๐Ÿ‘ค For Users

The following command retrieves all users in Active Directory along with their last logon time:

# Get all users and their last logon time
Get-ADUser -Filter * -Property DisplayName, SamAccountName, LastLogonTimestamp |
Select-Object DisplayName, SamAccountName, @{Name="LastLogon"; Expression={[datetime]::FromFileTime($_.LastLogonTimestamp)}} |
Export-Csv -Path "C:\Reports\UsersLastSignIn.csv" -NoTypeInformation -Encoding UTF8
  • ๐Ÿ” What It Does:

    • Get-ADUser: Retrieves user information from AD.
    • -Filter *: Fetches all users.
    • LastLogonTimestamp: Retrieves the last logon time for each user.
    • Export-Csv: Exports the results to a CSV file for review.
  • ๐Ÿ“ˆ Output: The command generates a CSV file named UsersLastSignIn.csv in the C:\Reports directory.

2. ๐Ÿ“š For Devices

Similarly, use the command below to get the last sign-in details for devices:

# Get all computers and their last logon time
Get-ADComputer -Filter * -Property Name, LastLogonTimestamp |
Select-Object Name, @{Name="LastLogon"; Expression={[datetime]::FromFileTime($_.LastLogonTimestamp)}} |
Export-Csv -Path "C:\Reports\DevicesLastSignIn.csv" -NoTypeInformation -Encoding UTF8
  • ๐Ÿ” What It Does:

    • Get-ADComputer: Retrieves computer information from AD.
    • LastLogonTimestamp: Retrieves the last logon time for each device.
    • Export-Csv: Saves the output to a CSV file named DevicesLastSignIn.csv.

๐Ÿ“Š Understanding the Commands

  • ๐Ÿ”น LastLogonTimestamp vs. LastLogon:

    • LastLogonTimestamp: Replicated across domain controllers but may be up to 14 days old.
    • LastLogon: Real-time but requires querying all domain controllers.
  • ๐Ÿ”น File Path: You can change the file path (C:\Reports\) to save the report to your preferred directory.


๐Ÿšจ Benefits of Using PowerShell

  • โณ Time-Saving: Automates a manual task.
  • ๐ŸŽจ Customizable: You can add or remove properties as needed.
  • ๐Ÿ“„ Portable Reports: The CSV files can be easily shared and analyzed.

๐Ÿ“š Conclusion

Using PowerShell to get reports on the last sign-in activity for users and devices in Active Directory is a straightforward and powerful approach. ๐Ÿš€ These commands not only provide valuable insights but also save time by automating repetitive tasks.

Try these commands in your environment and let me know in the comments if you have any questions or suggestions! ๐Ÿ˜Š


Tags: ๐Ÿ”ง PowerShell, ๐Ÿ”ฐ Active Directory, ๐Ÿ”’ IT Administration, ๐ŸŒ Last Logon Report, โš™๏ธ Automation

Back to Blog
ูƒูŠู ุชุตุฏู‘ุฑ ุดู‡ุงุฏุฉ SSL ู…ู† Azure Key Vault ูˆุชุซุจู‘ุชู‡ุง ุนู„ู‰ IIS

ูƒูŠู ุชุตุฏู‘ุฑ ุดู‡ุงุฏุฉ SSL ู…ู† Azure Key Vault ูˆุชุซุจู‘ุชู‡ุง ุนู„ู‰ IIS

ุฏู„ูŠู„ ุนู…ู„ูŠ ุฎุทูˆุฉ ุจุฎุทูˆุฉ ุจุงุณุชุฎุฏุงู… Azure CLI ูˆ OpenSSL ู„ูˆ ุงุดุชุฑูŠุช ุฃูˆ ูˆู„ู‘ุฏุช ุดู‡ุงุฏุฉ SSL ุฏุงุฎู„ Azure Key VaultุŒ ู‡ุชู„ุงู‚ูŠ ุฅู† ุงู„ุดู‡ุงุฏุฉ ู…ุด ู…ูˆุฌูˆุฏุฉ ูƒู…ู„ู ุชู‚ุฏุฑ ุชุญู…ู„ู‡ ู…ุจุงุดุฑุฉู‹ โ€” ูˆุฏู‡ ุชุตู…ูŠู… ู…ู‚ุตูˆุฏ ุนุดุงู† ุชุฃู…ูŠู† ุงู„ู€ private key. ููŠ ุงู„ู…ู‚ุงู„ุฉ ุฏูŠ...

Azure Migration: Advanced Strategies for 2026

Azure Migration: Advanced Strategies for 2026

ุฅุฐุง ูƒู†ุช ู„ุง ุชุฒุงู„ ุชุนุชู…ุฏ ุนู„ู‰ ุงุณุชุฑุงุชูŠุฌูŠุฉ Rehost (ุฃูˆ ู…ุง ูŠุนุฑู ุจู€ Lift-and-Shift) ู„ู†ู‚ู„ ุงู„ุฃุฌู‡ุฒุฉ ุงู„ุงูุชุฑุงุถูŠุฉ ูƒู…ุง ู‡ูŠุŒ ูุฃู†ุช ุจุจุณุงุทุฉ ุชู†ู‚ู„ ู…ุดุงูƒู„ูƒ ุงู„ู‚ุฏูŠู…ุฉ ุฅู„ู‰ ุจูŠุฆุฉ ุฌุฏูŠุฏุฉ ุฃุบู„ู‰ ุซู…ู†ุงู‹. ู‚ุจู„ ู„ู…ุณ ู„ูˆุญุฉ ุชุญูƒู… AzureุŒ ูŠุฌุจ ุฃู† ุชุชุจู†ู‰ ุงู„ู…ุคุณุณุงุช...