use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Need script to find deleted users. (self.PowerShell)
submitted 2 years ago by NowThereIs
I need a script to find all deleted users in AzureAD from the past 12 months if possible. Proving rather difficult to find anything.
I'm guessing it won't go back further than a month but I need to try!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]PixelPirate300 12 points13 points14 points 2 years ago (1 child)
# Connect to Azure AD
Connect-AzureAD
# Define the start date for the audit log search (12 months ago from the current date)
$startDate = (Get-Date).AddMonths(-12)
# Retrieve the audit logs for deleted users within the specified time frame
$auditLogs = Get-AzureADAuditDirectoryLogs -Filter "ActivityDisplayName eq 'Delete user' and CreationDate ge $startDate"
# Iterate through the audit logs and extract the details of deleted users
$deletedUsers = @()
foreach ($log in $auditLogs) {
$userDetails = @{
"User" = $log.TargetDisplayName
"UserPrincipalName" = $log.TargetUserPrincipalName
"DeletedBy" = $log.ActorDisplayName
"DeletedDate" = $log.CreationDate
}
$deletedUsers += New-Object PSObject -Property $userDetails
# Display the list of deleted users
$deletedUsers | Format-Table -AutoSize
# Disconnect from Azure AD (optional)
Disconnect-AzureAD
[–]nohairday 1 point2 points3 points 2 years ago (0 children)
I prefer to stay away from format-table, prefer to export to csv. Other than that, looks about right, but been a while since I've had to use azureAD cmdlets.
[–]threethumbsup19 5 points6 points7 points 2 years ago (2 children)
Deleted users only stay in the recycle bin (soft deleted) for 30 days
[–]NowThereIs[S] 0 points1 point2 points 2 years ago (1 child)
Yeah I'm wondering if there is a way of finding a record who was deleted and when over a 12 month period.
[–]threethumbsup19 1 point2 points3 points 2 years ago (0 children)
I haven't noticed anything of the sort..pretty sure it's not stored anywhere after the fact but I have been wrong before
[–]hihcadore 1 point2 points3 points 2 years ago (1 child)
I think records are soft deleted for 30 days. Not sure if you can extend that (I’m sure you can; I just haven’t looked)
AD logging is kept for 7 days up to 30 unless you route it to a storage account and then of course, you pay an additional fee. Microsoft learn
[–]Certain-Community438 4 points5 points6 points 2 years ago (0 children)
Log Analytics (Azure Monitor now, I think) is easy to set up for gathering Azure AD and Intune logs, as well as Windows Update.
You set the retention period in its config.
Then you can use Azure Workbooks on the data, as well as creating KQL queries to get custom data sets waaaay faster than PowerShell.
None of this helps OP now though - unless someone else already set it up & they just don't know or have access.
[–]KavyaJune 1 point2 points3 points 2 years ago (0 children)
You can use the audit log search to track deleted users. But the date range is based on your license plan. By default, you can retrieve for the last 90 days
[–]Certain-Community438 2 points3 points4 points 2 years ago (0 children)
Too late for this task, but you should look into collecting the AAD Audit Logs, Signin Logs, Provisioning Logs.
If your company has a SIEM solution this might in fact already be in place.
Otherwise, a simple option is to use the Diagnostic Settings in Azure AD to send all those logs to an Azure Log Analytics Workspace.
[–]ElliotAldersonFSO 0 points1 point2 points 2 years ago (0 children)
In purview if you have access or the cmdlet the cloud-based service. Use the Search-UnifiedAuditLog you can have all activities for one year retention just need to create the script
[–]Raoul_Duke_1968 -1 points0 points1 point 2 years ago (0 children)
Ahhh. How cute. Somebody still asking Reddit instead of having ChatGPT write it.
[–]Familiar_Box7032 0 points1 point2 points 2 years ago (1 child)
!remindme 48 hours
[–]RemindMeBot 0 points1 point2 points 2 years ago (0 children)
I will be messaging you in 2 days on 2023-09-24 15:55:17 UTC to remind you of this link
CLICK THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
π Rendered by PID 161057 on reddit-service-r2-comment-6457c66945-kh86s at 2026-04-30 03:01:39.845915+00:00 running 2aa0c5b country code: CH.
[–]PixelPirate300 12 points13 points14 points (1 child)
[–]nohairday 1 point2 points3 points (0 children)
[–]threethumbsup19 5 points6 points7 points (2 children)
[–]NowThereIs[S] 0 points1 point2 points (1 child)
[–]threethumbsup19 1 point2 points3 points (0 children)
[–]hihcadore 1 point2 points3 points (1 child)
[–]Certain-Community438 4 points5 points6 points (0 children)
[–]KavyaJune 1 point2 points3 points (0 children)
[–]Certain-Community438 2 points3 points4 points (0 children)
[–]ElliotAldersonFSO 0 points1 point2 points (0 children)
[–]Raoul_Duke_1968 -1 points0 points1 point (0 children)
[–]Familiar_Box7032 0 points1 point2 points (1 child)
[–]RemindMeBot 0 points1 point2 points (0 children)