Auditing new user accounts is a good way to track changes in your environment. This PowerShell script will provide you an output of accounts created in the last day.

You can further modify the script to how many days by adjusting the day count which is commented in the script.

We recommend running this in an Administrative PowerShell session or as a scheduled task, on a domain controller or system that has RSAT tools installed.

Copy and paste the below script in your favorite text editor and save it as audit_newusers.ps1.

The script will save results to a CSV named new_users_<date ran>.csv to the location where the script is located.

# -----------------------------------------------------------------
# New User Results
# Created by: Christopher Clai - www.syntaxbearror.io
# -----------------------------------------------------------------
# Version 1.0 (August 5th, 2019)
# -----------------------------------------------------------------
#
# Example of running the script:
# .\audit_newusers.ps1 
#
#
# ##### CHANGELOG ########
# Version 1.0
# 
#
#

Import-Module ActiveDirectory

# Alter the negative number to how many days back you want to go.
$range = ((Get-Date).AddDays(-1)).Date

# -----
# DO NOT EDIT ANYTHING BELOW THIS LINE
# -----

$fnmod = Get-Date -Format "yyyymmdd"
$fname = "new_users_" + $fnmod + ".csv"

Get-ADUser -Filter {whenCreated -ge $range} -Properties whenCreated | Export-CSV $fname -NoTypeInformation

Leave a Comment

Your email address will not be published. Required fields are marked *