r/PowerShell • u/MadBoyEvo • Jan 24 '21
Script Sharing The only command you will ever need to understand and fix your Group Policies (GPO)
In the last few months, I've limited my sharing to a minimum. Not by choice, but more like lack of time - being preoccupied with work and working on some cool PowerShell based projects. One of those projects which required a lot of effort and understanding of how Group Policies work is GPOZaurr. So today you get to meet it yourself - let me know what you think :-)
A blog post about it (to get more details):
Source codes:
GPOZaurr is a free PowerShell module that contains a lot of different small and large cmdlets. Today's focus, however, is all about one command, Invoke-GPOZaurr.
Invoke-GPOZaurrJust by running one line of code (of course, you need the module installed first), you can access a few built-in reports. Some of them are more advanced, some of them are for review only. Here's the full list for today. Not everything is 100% finished. Some will require some updates soon as I get more time and feedback. Feel free to report issues/improve those reports with more information.
GPOBroken – this report can detect GPOs that are broken. By broken GPOs, I mean those which exist in AD but have no SYSVOL content or vice versa – have SYSVOL content, but there's no AD metadata. Additionally, it can detect GPO objects that are no longer GroupPolicy objects (how that happens, I'm not able to tell - replication issue, I guess). Then it provides an easy way to fix it using given step by step instructions.
GPOBrokenLink – this report can detect links that have no matching GPO. For example, if a GPO is deleted, sometimes links to that GPO are not properly removed. This command can detect that and propose a solution.
GPOOwners – this report focuses on GPO Owners. By design, if Domain Admin creates GPO, the owner of GPO is the domain admins group. This report detects GPOs that are not owned by Domain Admins (in both SYSVOL and AD) and provides a way to fix them.
GPOConsistency – this report detects inconsistent permissions between Active Directory and SYSVOL, verifying that files/folders inside each GPO match permissions as required. It then provides you an option to fix it.
GPODuplicates – this report detects GPOs that are CNF, otherwise known as duplicate AD Objects, and provides a way to remove them.
GPOList – this report summarizes all group policies focusing on detecting Empty, Unlinked, Disabled, No Apply Permissions GPOs. It also can detect GPOs that are not optimized or have potential problems (disabled section, but still settings in it)
GPOLinks – this report summarizes links showing where the GPO is linked, whether it's linked to any site, cross-domain, or the status of links.
GPOPassword – this report should detect passwords stored in GPOs.
GPOPermissions – this report provides full permissions overview for all GPOs. It detects GPOs missing readmissions for Authenticated Users, GPOs that miss Domain Admins, Enterprise Admins, or SYSTEM permissions. It also detects GPOs that have Unknown permissions available. Finally, it allows you to fix permissions for all those GPOs easily. It's basically a one-stop for all permission needs.
GPOPermissionsAdministrative – this report focuses only on detecting missing Domain Admins, Enterprise Admins permissions and allows you to fix those in no time.
GPOPermissionsRead – similar to an administrative report, but this one focuses on Authenticated Users missing their permissions.
GPOPermissionsRoot – this report shows all permissions assigned to the root of the group policy container. It allows you to verify who can manage all GPOs quickly.
GPOPermissionsUnknown – this report focuses on detecting unknown permissions (deleted users) and allows you to remove them painlessly.
GPOFiles – this report lists all files in the SYSVOL folder (including hidden ones) and tries to make a decent guess whether the file placement based on extension/type makes sense or requires additional verification. This was written to find potential malware or legacy files that can be safely deleted.
GPOBlockedInheritance – this report checks for all Organizational Units with blocked inheritance and verifies the number of users or computers affected.
GPOAnalysis – this report reads all content of group policies and puts them into 70+ categories. It can show things like GPOs that do Drive Mapping, Bitlocker, Laps, Printers, etc. It's handy to find dead settings, dead hosts, or settings that no longer make sense.
NetLogonOwners – this report focuses on detecting NetLogon Owners and a way to fix it to default, secure values. NetLogonPermissions – this report provides an overview and assessment of all permissions on the NetLogon share.
SysVolLegacyFiles – this report detects SYSVOL Legacy Files (.adm) files.
Of course, GPOZaurr is not only one cmdlet - but those reports are now exposed and easy to use. This time I've not only focused on cmdlets you can use in PowerShell, but something that you can learn from and get the documentation at the same time.
To get yourself up and running you're just one command away:
Install-Module GPOZaurr -ForceHere are some screenshots to show you what the command does. Most of the reports have a description, a chart, data, and a solution to fix your issue.




Enjoy. If you like my work, I would be grateful for a star or two on Github. Thank you.
5
u/locke577 Jan 24 '21
I don't have a GitHub account to give stars, but enjoy some reddit platinum and gold on me
2
u/MadBoyEvo Jan 24 '21
Thank you. Appreciate it! It was not necessary, but happy to accept it :-D
2
u/locke577 Jan 24 '21
It's not necessary to provide great information and tools to people like you do, but you do it anyway. I think that deserves at least a month of ad free browsing
3
u/Thrussst Jan 25 '21
Can the command be scoped down to a single domain without excluding every individual domain? We have a large forest but have responsibility for only a single domain. I'm not even sure of every domain to exclude to be honest..
Amazing work!
4
u/MadBoyEvo Jan 25 '21
You can either use
Invoke-GPOZaurr -IncludeDomains ad.evotec.plOr you can use -ExcludeDomains parameter. It's also possible to target another forest using -Forest switch.
3
u/msplkra Jan 26 '21
Is there another way or some caveat to using include domain switch?
I am trying to scan only my domain, but the tool tries to discover every Ad in forest ,which fails.
I let it scan anyway overnight, but to no result.
3
u/MadBoyEvo Jan 26 '21
It depends where it fails and on which reports. You can try to choose each type separately. Some reports require whole forest scan for a simple reason - you can create GPO in one domain and link it in 5 other domains or to sites.
It's also possible there's some bug for other domains, but I need more data from you. Please submit logs on Github, make sure to run things with -Verbose switch, do some troubleshooting by running Invoke-GPOZaurr -Type <one,two,threereports only>
2
u/daunt__ Jan 26 '21
Our sysvol owner on Default Domain Policy and Default Domain Controllers Policy is BUILTIN\Administrators instead of DOMAIN\Domain Administrators.
The owner of the AD object is DOMAIN\Domain Administrators, I'm referring to the sysvol folder owner.
I doubt this causes any issues but the GPOZaurr report is flagging it as a problem. Can anyone confirm which one is default?
2
u/MadBoyEvo Jan 26 '21
So it works 2 ways:
When you deploy a new domain those 2 GPOs are as you describe - in safe, but not consistent state
It's not only on GPO Owners - if create new domain those two gpos when you hilight them will complain that the permissions on them mismatch and GPO tool will ask you if you want to fix it
Having said that - it's up to you if you want GPO owners consistent or not. BUILTIN\Administrators is WellKnownAdministrative group and from a safety point of view - it's safe.
I just believe that this is actually error on Microsoft side for any new domain that is created, and would consider it a bug on their side. Maybe there's a reason why can't it have proper owners in both places from the start - but I don't know. Maybe some day I'll went thru the effort to report this as a bug and see what happens.
Again - treat what GPOZaurr tells you as a learning exercise - don't trust it blindly. I did my effort, it works for me, I'm fine with the change - but again - you don't have to. None of the errors warrant to just follow whatever you said. It's safe to keep it as you have it.
Hope this helps
2
u/daunt__ Jan 26 '21
Thanks, I thought that might be the case but wasn't sure if a previous admin had been tinkering! I'll leave as is for now.
And thanks very much for the tool it's found a few issues and been very helpful for us :)
2
u/Thrussst Jan 26 '21
Could this be used to find/compare Windows Firewall settings? We are working to try to resolve a "too many cooks in the kitchen" scenario. It would be nice if this could identify which GPOs contained firewall settings. I found basic firewall on/off settings and the like in the report but not actual firewall rules...
2
u/MadBoyEvo Jan 26 '21
Yes it could be added. It takes some effort to build a reader for new rules.
2
u/Thrussst Jan 26 '21
Just making sure I wasn't missing it if already there. Once again, amazing work!
2
u/breid7718 Jan 26 '21
This is amazing - easily worthy of being a commercial product. I will be learning from this for a long time.
2
2
u/A50LRE Mar 11 '21
Thank you! I always use Powershell snippets to find disconnected GPO's, but this is ten times better. I reduced the GPO count with 60 policies!
1
32
6
6
u/overpourgoodfortune Jan 24 '21
Amazing - nice work OP. I've built gpo assessments for customers in the past and will be sure to add this to my toolkit for future engagements.
5
1
u/BureauCat55 Mar 10 '21
I'm interested in learning more about this seemingly excellent tool kit for AD, but the blog site is down right now: https://evotec.xyz/the-only-command-you-will-ever-need-to-understand-and-fix-your-group-policies-gpo/
2
u/MadBoyEvo Mar 10 '21
Unfortunately, my website was hosted in OVH SBG1. Today OVH had a fire https://www.reuters.com/article/us-france-ovh-fire-idUSKBN2B20NU which basically destroyed SBG2, and 4 out of 12 rooms in SBG1. It may or may not be that my server is destroyed as well. I now need to plan the recovery of the website on new hosting. Planning to do that this week.
2
u/ka-splam Mar 11 '21
I just came back to your article on resetting passwords remotely today, and found it wouldn't load, then came to Reddit to check if you were ok and if anything happened to your site.
Glad you are ok, and I hope the recovery is easy :)
(I found the script saved and fixed the password, so not for that reason!)
2
u/MadBoyEvo Mar 11 '21
The website should be back now. I've restored it from backups. Need to do some changes around, but generally, it's back. There's a reason why I keep everything on GitHub (where all code is part of modules anyway) and also synced to OneDrive. Unfortunately most likely if the old server won't be back I will lose some data that I need. Oh well.
I did update the password reset remotely a while back so it's more user-friendly. I sometimes come back to articles and improve them.
/u/BureautCat55 feel free to check the article
1
1
u/j_bombay Dec 16 '21
Is there anything like this with powershell we can use for intune configuration profiles, defender for endpoint?
1
u/MadBoyEvo Dec 16 '21
https://microsoft365dsc.com/ would be my first guess. 2nd guess is that in 2022 I will either write something like that or enhance M365DSC :)
1
u/Lazy_Republic_1917 Feb 21 '24
Hi All,
I read in OP comments that running this in production is not recommended. Is it safe to just run the invoke to generate the reports? I'd like to just get a general picture of PRD without making any changes. Thanks!
1
u/MadBoyEvo Feb 21 '24
I never said it's not safe to run in production. I said understand what will happen and what it's doing before running it in production. Invoke-GPOZaurr command is report only and you can try running it using non-priviledge account first.
1
u/Lazy_Republic_1917 Feb 21 '24
Excellent thank you very much. Sorry if I misunderstood. My environment only has PRD so I wanted to be sure. I’ve been using piecemeal ps commands up until now, this looks amazing. Thanks!
3
u/Flasharn Jan 24 '21
You guys always build and provide such beautiful scripts, you are the reason I continue improve and learn, thanks!
3
3
3
3
u/phartnocker Jan 24 '21
Thanks. I’m embarking on a gpo project I wasn’t sure how to tackle. This will help.
3
3
u/Admin-AF Jan 25 '21
This looks amazing. Addressing a pain point in most orgs and also educational around how GPOs work overall. We don’t have an active GPO clean up project at my work right now, but we may after I run a report or two...
2
2
u/haxelhimura Jan 26 '21 edited Jan 26 '21
Holy forking shirtballs this is exactly what I needed to fix our GPO structure.
You my friend are a God among men.
EDIT: Hey u/MadBoyEvo quick question, which order would you suggest going in to resolve the issues this finds? Tab by tab starting with the first one, Broken Group Policies?
2
u/JamPickleP Jan 24 '21
This is awesome.
Thank you man. I'll be sure to head over to Git this evening.
1
1
-3
u/GenghisChaim Jan 24 '21
This is only for AD? Doesn't consider Local GPOs at all?
7
u/MadBoyEvo Jan 24 '21
Yes, only for AD. it doesn't analyze local GPOs - not yet. I've started working on Invoke-GPOZaurrSupport which is a wrapper around gpresult and it's supposed to have GPOAnalysis report built-in - but it's a long way - not a top priority for now.
-1
Jan 24 '21
Soooo... this give me what extra to gpresult?
2
u/MadBoyEvo Jan 24 '21
Not really. There's nothing on the market that does this for free as far as I know. It's directed for overall analysis of GPOS rather than checking what's deployed on workstations.
If you want gpresult alternative you can try Invoke-GPOZaurrSupport although the cmdlet is not finished, and doesn't do GPO Content analysis. But sometime in the future I expect it will be able to replace it fully with modern look and much more data to analyze.
-5
Jan 25 '21
Given Group Policy is a thing of the past - wouldn’t you be better off focusing on a CSP equivalent?
7
u/MadBoyEvo Jan 25 '21
Weirdly - thing of a past getting 400 votes on PowerShell Reddit, 2000 upvotes on sysadmin, and many more on Facebook/Twitter with 100-300 people reading the blog all the time ever since I posted it.
Is it a thing of the past? It may not be updated anymore, but it's hardly a thing of the past.
Intune is supposed to take over and some people are focusing on it, but it will take 10+ years for most orgs to migrate. Until then those companies will be attacked and they need to know what is what in their GPOs.
1
Jan 25 '21
Not saying it’s pointless dude just saying that there’s nothing like it for modern management and potentially a bigger opportunity for your efforts that’s all
2
u/MadBoyEvo Jan 25 '21
I do switch from AD to Office 365/Azure from time to time. It depends on who needs me more and whether my Clients have that kind of requirement. After all, someone has to pay for my time investment. Everything you get for free, someone paid for one way or the other.
2
Jan 25 '21
Hah share the love, I commend you on your patience to answer the amount of questions you’ve probably had and ultimately what you have created! Cheers
5
Jan 25 '21
A thing of the past!? Haha. Oh boy.
1
Jan 25 '21
Yea I get it’ll be around - heck i argue with MS architects daily that CSP just isn’t a featured as GPO but the fact remains it will be driven by a monopoly with an agenda - not for the love of IT admins lol
-4
3
13
u/Snak3d0c Jan 24 '21
Very nice work! 70% of what you did, I did for myself. Only mine output is simple csv, your presentation is a lot nicer with the html reports.
My project is still ongoing, moving +25 ou's into 3. Merging all what can be merged and remove everything that can be removed. Took just short of 6month to do the computer gpo's. Tomorrow We're starting on the user policies.
Like you said, you need an intricate knowledge of GPO to grasp your output and its code. Writing those cmdlets have lead to my promotion.
Very nicely done !