Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To extract the last login date of inactive users for exporting using PowerShell, you can use the Get-ADUser cmdlet and the LastLogonDate attribute. You can also filter the results to show only inactive users using the LastLogonDate attribute.

Here is an example script that extracts the last login date of inactive users and exports the data to a CSV file:

$inactiveDays = 90 # Number of days of inactivity
$exportPath = "C:\Users\Username\Documents\InactiveUsers.csv" # Export file path

# Get inactive users
$inactiveUsers = Get-ADUser -Filter {LastLogonDate -lt (Get-Date).AddDays(-$inactiveDays)} -Properties LastLogonDate | Where-Object {$_.Enabled -eq $true}

# Select required properties and export to CSV
$inactiveUsers | Select-Object Name, SamAccountName, LastLogonDate | Export-Csv $exportPath -NoTypeInformation

Note: This script assumes that you have the Active Directory module installed on your computer. If not, you can install it by following the instructions on the Microsoft website.