r/PowerShell • • Sep 16 '18

Script Sharing PSWinReporting - Monitoring active directory events and sending it to Email, Microsoft Teams, Slack, SQL

For those who don't know this module it's purpose is simple - monitoring Active Directory for events such as creating new users, adding users to groups, deleting users and so on. If you've ever wondered who added this guy to Domain Admins this tool can tell you.

By default (the old version) it was only able to send it to Email with nice reports. New version adds:

  • Support for Event Forwarding – monitoring one event log instead of scanning all domain controllers

  • Support for Microsoft Teams – Sending events as they happen to Microsoft Teams (only supported when forwarders are in use)

  • Support for Slack – Sending events as they happen to Slack (only supported when forwarders are in use)

  • Support for Microsoft SQL – Sending events directly to SQL (some people prefer it that way) - including create table, alter table and insert rows with table mapping in place

  • Support for backing up old archived logs (moves logs from Domain Controllers into chosen place)

  • Support for re-scanning logs from files – a way to recheck your logs for missing information

The last one is still in progress but should be usable soon.

Blog about new release (how to and so on): https://evotec.xyz/pswinreporting-forwarders-microsoft-teams-slack-microsoft-sql-and-more/

Module page: https://evotec.xyz/hub/scripts/pswinreporting-powershell-module/

Sources are on GitHub, and installable from PowershellGallery (preferred way). It utilizes following modules for different functionalities (available on github/powershellgallery)

129 Upvotes

12 comments sorted by

2

u/sup3rlativ3 Sep 17 '18

Seems like a great tool. Your blog post doesn't make it clear though, how to get it all working if you want multiple alerting options. For example, I would like slack and email notifications because some people like to know straight away e.g. me while others would just like a summary e.g. my manager.

I've setup event log forwarding and can confirm that is working. I have copied the same code from the blog post and had it create the events etc. The last piece is the script that is called from the scheduled task. I copied the first iteration of the script from the blog post and enabled the slack notifications but then the second iteration is missing the slack portion. I would also like it to report to me directly and as it stands it seems like I need to specify a channel rather than myself?

I'm not sure if I'm just being dense or if this is more complicated than it should be. Is there a function to enable certain notifications? Some clarity would be nice to get everything working.

2

u/MadBoyEvo Sep 17 '18

This blog assumes you're already using this tool. Hence why no description of some features. There are 7 other blogs about first way to work with it.

Anyways.. there are 2 main scripts here and as you noticed they are not identical. This is because they work in 2 different ways.

If you go to GitHub there is Examples folder: https://github.com/EvotecIT/PSWinReporting/tree/master/Examples which is kind of copy/paste to blog for scripts.

Now the 2 scripts I'm talking about is:

  • RunMe-Report.ps1

  • RunMe-TriggerOnEvents.ps1

RunMe-Report provides an overview of all events. When you run it it will scan for defined period of time. Whether it will be 5 events, 500, 5000 it will bundle this as one and send via email or via excel or via csv or via html or all above. It doesn't have Slack, Teams or SQL. For very simple reason it doesn't make sense to send 500 events weekly at one time to Slack. This is your managers script, your overview script and this is your script that you setup with email details and put it into Task-Scheduler yourself. Separately. I would advise to put it 00:05 or so to be run once per day. Then you setup the dates you want it to run on and it will do the rest for you (weekly, monthly, daily, just on mondays or so). That's it. It supports both ways (scanning all DC's) or scanning just Forwarder. The difference will be .. if you just started with forwarder it will have small data. But after few days it will catch up. Also the difference will be speed. With forwarder most likely count will be within seconds/minutes. Without it minutes/hours.

RunMe-TriggerOnEvents works in a way 1 event at the time. This is where you get slack, teams, sql. Since it doesn't check all logs but just 1 event it doesn't bundle them, it doesn't prepare reports or do other stuff. It can be used to trigger on an event such as when backup of logs is done move the logs. This is expandable and probably could catter few things.

This means you have to setup 2 scheduled tasks. 1 for your manager/yourself that will run 00:05 (and check if date conditions matches). 1 that is kind of setup automatically when you use my scripts that acts on events. And this is what you get in Slack or Teams.

As for sending things to chat... well Teams doesn't support it. As for slack... according to PSSlack documentation you can simply put "Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name." so just experiment with it.

2

u/[deleted] Sep 17 '18 edited Sep 17 '18

I used the sample config here to set everything in $ReportTimes to $false except PastDay, but it still tries to show me everything from the past week. Anyone else?

Ninja edit: Never mind, I see the one-day report. It also generates a one-week report, though, and I'm not sure why.

2

u/MadBoyEvo Sep 17 '18

Can you post log output? I will check code as it was last minute change that I did to dates. Maybe I mixed something up.

2

u/MadBoyEvo Sep 17 '18

Just rerun this. Set pasthour to true, pastday to true and it generated me 2 reports.

1st:

[2018-09-17 20:13:08][i] Processing report for dates from: 09/17/2018 19:00:00 to 09/17/2018 20:00:00

2nd:

[2018-09-17 20:15:43][i] Processing report for dates from: 09/16/2018 00:00:00 to 09/17/2018 00:00:00

Seems to be fine.

2

u/MadBoyEvo Sep 17 '18

if you enable multiple reports as in there are multiple true values it will generate multiple reports. you must have somewhere there additional true.

2

u/[deleted] Sep 17 '18

This was it. I wasn't paying attention and there was indeed another true in there. Thanks! This module is great!

2

u/Betsy-DeVos Sep 16 '18

Neat tool, I dont have much use for the overall script in my current role but I will definitely be using the teams message support for some reporting that I want to do once our lazy office/sharepoint admins enable the features I asked for 3 months ago.

2

u/halbaradkenafin Sep 16 '18

You might also be interested in PoshBot then, it hooks into Teams now and gives you another option for automating things and getting people away from RDP and similar.

2

u/MadBoyEvo Sep 17 '18

I actually have plans for PoshBot to integrate some of my scripts into it. But it's a bit special to set it up.

4

u/Haraballz Sep 16 '18

This looks really nice.
Will have to try this when I go to work tomorrow :)

0

u/[deleted] Sep 16 '18

[deleted]

2

u/MadBoyEvo Sep 16 '18

If it doesn't open an issue on GitHub. I'll try to help and fix code if needed. It's supposed to be flexible but I did test it only on couple of systems / environments. Always good to get another angle. What's most interesting for you in this?