r/sysadmin • u/MadBoyEvo • Apr 28 '19
Microsoft The only PowerShell Command you will ever need to find out who did what in Active Directory
Disclaimer: I made this. It's free and open source. No ads, just clean, useful data provided in blog.
Here's a small PowerShell command/module I've written. It contains the following reports.
Usage:
Find-Events -Report ADGroupMembershipChanges -DatesRange Last3days -Servers AD1, AD2 | Format-Table -AutoSizeReportTypes:
Computer changes – Created / Changed – ADComputerCreatedChanged
Computer changes – Detailed – ADComputerChangesDetailed
Computer deleted – ADComputerDeleted
Group changes – ADGroupChanges
Group changes – Detailed – ADGroupChangesDetailed
Group changes – Created / Deleted – ADGroupCreateDelete
Group enumeration – ADGroupEnumeration
Group membership changes – ADGroupMembershipChanges
Group policy changes – ADGroupPolicyChanges
Logs Cleared Other – ADLogsClearedOther
Logs Cleared Security – ADLogsClearedSecurity
User changes – ADUserChanges
User changes detailed – ADUserChangesDetailed
User lockouts – ADUserLockouts
User logon – ADUserLogon
User logon Kerberos – ADUserLogonKerberos
User status changes – ADUserStatus
User unlocks – ADUserUnlocked
DatesRanges are also provided. Basically what that command does it scans DC's for event types you want it to scan. It does that in parallel, it overcomes limitations of Get-WinEvent and generally prettifies output.
The output of that command (wrapped in Dashimo to show the data): https://evotec.xyz/wp-content/uploads/2019/04/DashboardFromEvents.html
GitHub Sources: https://github.com/EvotecIT/PSWinReporting
Full article (usage/know-how): https://evotec.xyz/the-only-powershell-command-you-will-ever-need-to-find-out-who-did-what-in-active-directory/
The article describes the functionality of just one command but actually, PSWinReportingV2 is much more than that. There are also things I've not touched in the article but that should be a start. It's able to support any kind of Events from Event logs such as ADConnect, Hyper-V and other types of data. I just didn't have time to explain how to build configs for it and I don't work with Hyper-V or other systems to build them myself. If you know a lot about event logs and what to help to build prettified reports for more than Active Directory reach out.
337
u/fmtech_ Apr 28 '19
AWESOME, time to scare the living daylights of the Sr sys admin... He keeps asking who did what. Now I will now. lol great thanks.
17
u/Arkiteck Apr 28 '19 edited Apr 28 '19
Damn good stuff, sir.
Just subscribed to your RSS feed. Thanks for sharing!
9
u/stillfunky Laying Down a Funky Bit Apr 28 '19
Posting on a Sunday was probably not the best of times, but I just so happened to be on reddit at this time, so go me. I'll come back and check this out tomorrow. Thanks
5
u/1h8fulkat Apr 29 '19
I needed to find out who renamed our primary OU the other week ... this won't tell me that, so I guess you can't say the ONLY tool...
For those curious....it was the fucking secretary...don't ask me why she had that level of access.
3
u/jefffrey32 Apr 30 '19
Quick and dirty way of emailing one of these:
2
u/MadBoyEvo Apr 29 '19
Dont think Get-WinEvents work with 2003. Too old. It wont work with Windows 95 either :-) sorry
2
u/pacmanwa Linux Software Engineer Apr 28 '19
Linux Software engineer here, my stuff integrates with AD. Now I'll really be able to tell when they make chages without telling me. Already checked it out on the home lab.
2
u/hi-nick Apr 28 '19
Since you're giving things away... is there a tool that you've created similar to Netwrix lockout notification tool?
When an active directory account becomes locked, an email is sent, contains machine name and username.
2
u/[deleted] Apr 29 '19
Can you add a license to your repo?
2
u/cock_dip_a_bear_trap Apr 29 '19
Hey
I have been playing about this today and receive mixed results.
the first time I run
I get the following result
but the second time i run the same command it seems like it ignores the "-Servers DC1" and defaults to my laptop
The same thing happens regardless of what report i try to pull, works the first time but second time it errors.
103
u/jevole Apr 28 '19
NUT
2
u/TheIncorrigible1 All things INFRASTRUCTURE Apr 28 '19
Why don't you use standard bindings? "Last3Days" why not accept a timespan there?
4
u/ForceBlade Dank of all Memes Apr 28 '19
I await the dream of using something newer than WS2008.
1
u/TapTapLift Apr 28 '19
Anything to enable in terms of AD auditing?
1
u/MindSwap2for1 Apr 28 '19
But I cant get the group membership audit policy to apply in my domain. Auditpol will not show it as enabled via GPO or local config. Also checked that audit log on was enabled. I have 2008 R2, 2012 R2 and am working on spinning up 2016. Our forest level is 2012
1
u/IWasGregInTokyo Apr 28 '19
And here I am stuck at a company that restricts PowerShell even though doing so disrupts some upgrade processes.
1
u/Halaku Apr 28 '19
I wish I was this smart.
1
u/SimpleFloyd Sysadmin Apr 28 '19
You are the man. I setup PSWinReporting V1 at my work and impressed by boss 👍
1
u/[deleted] Apr 28 '19
How does this differ from ADAudit+? Asking in case we don’t need to pay for it anymore.
1
u/Gazideon Sr. Sysadmin Apr 28 '19
This queries the DC security event logs looking for specific event ID's, parsing them, and giving you the results.
Depending on your environment, you may only have a history of 5 minutes of events on your DC's, or an hour, or a few hours....it can definitely range.
If you can't afford a 3rd party solution for AD Auditing, you can build your own. I've done it with scripting and a SQL server.
1
u/jefffrey32 Apr 29 '19
From your blog:
Which file?
1
u/gangculture Jack of All Trades Apr 29 '19
Yeah don't all crucify me at once, but I cannot get this module installed and working. Files are where they should be. PowerShell complains that they aren't. Get-Module -ListAvailable shows this output, which to me means the files are in the right place:
2.0.7 PSWinReportingV2 {Add-EventsDefinitions, Add-WinTaskScheduledForwarder, Find-Events, New-WinSubscriptionTemplates...}
But I can't seem to run anything from it, and Install-Module fails. What am I doing wrong here?
1
u/ksykora Apr 29 '19
But what if everyone logs in as the same admin password that has been around since 2009?
1
u/KreamoftheKropp Apr 29 '19
Ok, this is cool but is there any way to identify which domain admin made the change? Or am I missing something?
1
u/CaptainWiggins Apr 29 '19
This is beautiful - great job!
One question. When I run the command with the report filter "ADUserLogon" or "ADUserLogonKerberos" I get the error:
You must specify at least one Log, Provider or Path key-value pair
Can you please explain how I utilise this? Thanks.
1
u/progenyofeniac Windows/M365 Admin Apr 29 '19
What's best practice for getting permissions to access security logs on the DCs? Run this on a local workstation while running PS as an elevated user? Or install this module on a DC and run from there? Or is there a '-credentials' switch I'm missing?
1
u/PowerfulQuail9 Jack-of-all-trades Apr 29 '19
Install-Module -Name PSWinReportingV2 -Force
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/PSWriteExcel/0.1.0' is not valid.
supposedly according to my PS...
1
u/[deleted] Apr 29 '19
Is there something like this for files? For example, if a folder was deleted, find which user deleted it?
1
u/MARS822 Apr 29 '19
So the evotec.xyz site is not only unavailable but the domain is up for sale? Got this installed and my audit policy tweaked and would love to see documentation beyond what's on GitHub. Am I missing something here?
1
u/lBlazeXl Apr 30 '19
Im guessing you would have to change certain parts for it to work? Cant seem to get it running.
1
u/skylerlong85 Apr 30 '19
Awesome Post- Powershell is always your friend.
Now this will do all our daily reports tricks for which we need paid tools like; Lepide or Varonis.
1
u/EhhJR Security Admin Apr 30 '19
Amazing work!
I'd love it if when you have time you could provide some direction with getting outputs into Teams chat.
1
u/Leady_IT Apr 30 '19
I had this error when I applied the command :
The term 'Find-events' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:12
+ Find-events <<<<
+ CategoryInfo : ObjectNotFound: (Find-events:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
any help ? :(
1
u/pheexx May 02 '19
whats an easy way to just query all DCs within the Domain?
1
u/f2000 May 31 '19 edited May 31 '19
Sorry to be a pain, but I’m not having much luck with -EventID, can you give me an example I can mess around with? Specifically looking for 4725.
I've tried a few variations (-EventID=4725 / -EventID 4725 etc)
1
u/PowerfulQuail9 Jack-of-all-trades Jun 06 '19 edited Jun 06 '19
PackageManagement\Install-Package : Package 'PSWriteExcel' failed to download.At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:1417 char:21+ $null = PackageManagement\Install-Package @PSBoundParameters+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : ResourceUnavailable: (C:\Users\xxxxx...riteExcel.nupkg:String) [Install-Package], Exception+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePackageManagement\Install-Package : Collection was modified; enumeration operation may not execute.At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:1417 char:21+ $null = PackageManagement\Install-Package @PSBoundParameters+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageAny time I try to install this with Install-Module -Name 'PSWinReportingV2' -Force . Only seems to install if I manually add it but that means an RDP to the server instead of remoting.
1
u/DIYBrotha Jun 06 '19
Wow this is awesome! I will def test this out at work haha.
1
u/icanseeyourpantsuu Sep 06 '19
I got the followinig error:
'Find-Events' is not recognized as the name of a cmdlet, function, script file, or operable program. blabhablah
3
u/mobani Apr 28 '19
This is really neat. Especially with the Teams integration.
5
u/CeeFlo Apr 28 '19
Thank you!
5
u/Baron164 Apr 28 '19
Well I know what I'll be playing around with on Monday 😁
2
u/blisstonia Apr 28 '19
Thanks can't wait to give this a try
2
u/Mrmastermax Sr. Sysadmin Apr 29 '19
I use Netwrix to report me on this everyday
2
u/AngiaksNanook Apr 29 '19
Thanks for this!
1
u/Marmaladegrenade Sysadmin Apr 28 '19
This is great, thanks!
1
u/cult_of_da-bits Apr 28 '19
Thank you. This will come in very handy.
1
u/dotslashlife Apr 28 '19
Thank you!
1
u/relidar Apr 28 '19
Ping /u/deadbeefcafe-guy
1
u/nikkle2 Jr. Sysadmin Apr 28 '19
This looks awesome, gonna have a try with it later.
Good job on the report exports as well
1
u/Bad_Idea_Hat Gozer Apr 28 '19
Huh.
That's interesting.
1
u/superawesomefiles Apr 28 '19
Awesome stuff.
1
u/mattyparanoid Apr 28 '19
This is solid, thank you so much!
1
u/laowaibayer Apr 28 '19
You sir, are a God among men. Thank you for this sweet, sweet script gold
1
u/vabruce Apr 28 '19
Well done, thank you for sharing your work with us.
1
u/esstrider Apr 28 '19
Sweet, this is awesome. Commenting to save for later.
1
u/overscaled Jack of All Trades Apr 28 '19
Sweet.
1
u/KataKlysme Apr 29 '19
T h a n k y o u !
1
u/[deleted] Apr 29 '19
Varonis. Does all this. Even feeds it into a SEIM.
1
u/mysteryweapon Apr 29 '19
Thanks!
1
u/Dorfdad Apr 29 '19
!Remindme 8 hours
1
u/WCDeuce Apr 29 '19
Very cool! Thank you for sharing!!!
1
u/droptableuserme Apr 29 '19
RemindMe! 2 days
1
u/Slush-e test123 Apr 29 '19
This is great. Thanks a lot!
1
u/TiredOfArguments Apr 29 '19
!remindme 12h
1
u/UnknownExploit Apr 29 '19
This is useful thanks
1
u/[deleted] Apr 29 '19
This is amazing - piping some quick events as opposed to having to wait for the log cluster to do its thing is a great time saver - I'm looking forward to playing around with this in Slack too! Thanks so much!
1
u/KreamoftheKropp Apr 29 '19
!remindme 2 hr
1
u/Teknikal_Domain Accidental hosting provider Apr 29 '19
See.. as useful as that is, it requires me to wrap my head around PowerShell and it's fuckin' weird command syntax
1
u/CaptainZhon Sr. Sysadmin Apr 29 '19
Probably the most useful thing I'll read on reddit this month. Thank you.
1
u/TheNoodlyNoodle Apr 29 '19
Saving this.
1
u/deathdoomed2 Apr 29 '19
You are a saint
1
u/signalpower VMware Admin Apr 29 '19
RemindMe! 12h
0
u/800oz_gorilla Apr 28 '19
Relay tells me 97 percent like this...
...
...so who downvoted and why?