Generate a List of Active Directory Users and Their Last Logon Dates

Understanding user activity in Active Directory is key for maintaining security and compliance. This PowerShell script retrieves a list of active users along with their last logon dates. Administrators can use this information to identify inactive accounts and optimize their user management processes.
At ServerEngine, we develop innovative solutions to enhance your IT management experience. Explore our software at [ServerEngine](https://serverengine.co).
### Step 1: Import the Active Directory Module
Ensure that the Active Directory module is imported to access the required cmdlets for retrieving user information.
“`powershell

Import-Module ActiveDirectory

### Step 2: Define the Function to Retrieve User Logon Data
We will create a function called `Get-ADUserLogonInfo` that fetches each users last logon date from Active Directory.
“`powershell

function Get-ADUserLogonInfo {
    $users = Get-ADUser -Filter * -Properties LastLogonDate | Select-Object Name, LastLogonDate
    return $users
}

### Step 3: Execute the Function and Display the Results
Now youll execute the function and display the output in a readable format.
“`powershell

$logonInfo = Get-ADUserLogonInfo
$logonInfo | Format-Table -AutoSize

### Step 4: Export the Results to a CSV File (Optional)
If you wish to save the results for future review, you can export them to a CSV file.
“`powershell

$logonInfo | Export-Csv -Path "C:\Path\To\Your\ADUserLogonInfo.csv" -NoTypeInformation

### Conclusion
This script helps administrators maintain oversight of user activity in Active Directory, supporting better security practices and account management. For more effective IT solutions, check out [ServerEngine](https://serverengine.co).