How to view active and inactive users in Active Directory using PowerShell scripts?

Read on to know how to view the list of active and inactive users report in Active Directory (AD) using PowerShell and how you can get it done easier with ADManager Plus, a comprehensive Active Directory management solution.

Windows PowerShell

Active users report:

  • Identify the domain for which the active users report is to be generated.
  • Create and compile the script for generating the active users report. Execute the script in PowerShell.
  • Sample script to view and export active AD users:
 Copied
PS C:\> Import-module activedirectory
$DaysInactive = 30
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADUser -Filter {LastLogonTimeStamp -gt $time -and enabled -eq $true} -Properties LastLogonTimeStamp | select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('yyyy-MM-dd_hh:mm:ss')}} | export-csv C:\Scripts\activeusers.csv -notypeinformation
Click to copy entire script

Inactive users report:

  • Identify the domain for which the inactive users report is to be generated.
  • Create and compile the script for generating the inactive users report. Execute the script in PowerShell.
  • Sample script to view and export inactive AD users report:
 Copied
PS C:\> Import-module activedirectory
$DaysInactive = 30
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -eq $true} -Properties LastLogonTimeStamp | select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString('yyyy-MM-dd_hh:mm:ss')}} | export-csv C:\Scripts\inactiveusers.csv -notypeinformation
Click to copy entire script

ADManager Plus

Active users report:

  • Navigate to Reports > Custom Reports > User Reports > Active Users
  • Select the Domain for which you wish to generate the active users report. Click Generate. You can even export the report as CSV, PDF, XLSX or HTML.

Screenshot

View active users in Active Directory using ADManager Plus

Inactive users report:

  • Navigate to Reports > User Reports > Logon Reports > Inactive Users.
  • Select the Domain for which you wish to generate the inactive users report. Click Generate. You can even export the report as CSV, PDF, XLSX or HTML.

Screenshot

View inactive users in Active Directory using ADManager Plus

» Start 30-day Free Trial

Although generating and exporting user reports with native tools like PowerShell looks simple, it comes with a few limitations like:

  • PowerShell scripts can be run only from computers which have the Active Directory Domain Services role installed in them.
  • The syntax, parameters and iterations need to be correct. A typo or incorrect syntax might be difficult to spot and rectify especially when the script is long.
  • The script needs to be rewritten if the report needs to be generated for a different time period.

ADManager Plus helps you get the same information from its web based GUI console through pre-defined reports that list active and inactive users. Further, you can also perform management actions such as modification, deletion,etc right from the reports. The reports in ADMP also give you the option to automate the removal of inactive AD accounts. Learn more about it here.

  • Embark on your script-free AD management, reporting, and automation journey with ADManager Plus.
  •  
  • By clicking 'Start your free trial now', you agree to processing of personal data according to the Privacy Policy.
  • Thanks
  • Your download should begin automatically in 15 seconds. If not, click here to download manually.

Related Powershell How-to Guides:

Email Download Link