{"id":807,"date":"2012-09-03T00:47:05","date_gmt":"2012-09-02T16:47:05","guid":{"rendered":"http:\/\/www.jhouseconsulting.com\/?p=807"},"modified":"2012-09-04T00:27:26","modified_gmt":"2012-09-03T16:27:26","slug":"finding-orphaned-group-policy-objects","status":"publish","type":"post","link":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2012\/09\/03\/finding-orphaned-group-policy-objects-807","title":{"rendered":"Finding Orphaned Group Policy Objects"},"content":{"rendered":"<p>Group Policy Objects (GPOs) are stored in two parts:<\/p>\n<ol>\n<li>GPC (Group Policy Container). The GPC is where the GPO stores all the AD-related configuration under the\u00a0CN=Policies,CN=System,DC=&#8230; container, which is replicated via AD replication.<\/li>\n<li>GPT (Group Policy Templates). The GPT is where the GPO stores the actual settings located within SYSVOL\u00a0area under the Policies folder, which is replicated by either File Replication Services (FRS) or Distributed File System (DFS).<\/li>\n<\/ol>\n<p>This script will help find GPOs that are missing one of the parts, which therefore makes it an orphaned GPO.<!--more--><\/p>\n<p>A GPO typically becomes orphaned in one of two different ways:<\/p>\n<ol>\n<li>If the GPO is deleted directly through Active Directory Users and Computers or ADSI edit.<\/li>\n<li>If the GPO was deleted by someone that had permissions to do so in AD, but not in SYSVOL. In this case,\u00a0the AD portion of the GPO would be deleted but the SYSVOL portion of the GPO would be left behind.<\/li>\n<\/ol>\n<p>Although orphaned GPT folders do no harm they do take up disk space and should be removed as a cleanup task.<\/p>\n<p>Lack of permissions to the corresponding objects in AD could cause a false positive. Therefore, verify GPT\u00a0folders are truly orphaned before moving or deleting them.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Here is a screen shot showing the output of the script, which had identified 4 orphaned GPTs.\u00a0Note the count of GPC and GPT&#8217;s.<\/p>\n<p><a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO1.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone  wp-image-809\" title=\"OrphanedGPO1\" src=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO1.png\" alt=\"\" width=\"535\" height=\"206\" srcset=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO1.png 892w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO1-300x115.png 300w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO1-768x295.png 768w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Here is a follow-up screen shot showing the output of the script after the 4 orphaned GPTs had been removed. Again note the count of GPC and GPT&#8217;s.<\/p>\n<p><a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO2.png\"><img decoding=\"async\" class=\"alignnone  wp-image-810\" title=\"OrphanedGPO2\" src=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO2.png\" alt=\"\" width=\"535\" height=\"170\" srcset=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO2.png 892w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO2-300x95.png 300w, https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/OrphanedGPO2-768x244.png 768w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/a><\/p>\n<p><strong>The <a href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-content\/uploads\/2012\/09\/FindOrphanedGPOs.ps1_.txt\">FindOrphanedGPOs.ps1<\/a>\u00a0script:<\/strong><\/p>\n<pre class=\"brush: powershell; auto-links: false; title: ; toolbar: false; notranslate\" title=\"\">\r\n&lt;#\r\nThis script will find and print all orphaned Group Policy Objects (GPOs).\r\n\r\nGroup Policy Objects (GPOs) are stored in two parts:\r\n\r\n1) GPC (Group Policy Container). The GPC is where the GPO stores all the AD-related configuration under the\r\n CN=Policies,CN=System,DC=... container, which is replicated via AD replication.\r\n2) GPT (Group Policy Templates). The GPT is where the GPO stores the actual settings located within SYSVOL\r\n area under the Policies folder, which is replicated by either File Replication Services (FRS) or\r\n Distributed File System (DFS).\r\n\r\nThis script will help find GPOs that are missing one of the parts, which therefore makes it an orphaned GPO.\r\n\r\nA GPO typically becomes orphaned in one of two different ways:\r\n\r\n1) If the GPO is deleted directly through Active Directory Users and Computers or ADSI edit.\r\n2) If the GPO was deleted by someone that had permissions to do so in AD, but not in SYSVOL. In this case,\r\n the AD portion of the GPO would be deleted but the SYSVOL portion of the GPO would be left behind.\r\n\r\nAlthough orphaned GPT folders do no harm they do take up disk space and should be removed as a cleanup task.\r\n\r\nLack of permissions to the corresponding objects in AD could cause a false positive. Therefore, verify GPT\r\nfolders are truly orphaned before moving or deleting them.\r\n\r\nOriginal script written by Sean Metcalf\r\n<blockquote class=\"wp-embedded-content\" data-secret=\"nXOKTDzfht\"><a href=\"http:\/\/blogs.metcorpconsulting.com\/tech\/?p=1076\">Powershell Code: Finding Orphaned Group Policy Objects<\/a><\/blockquote><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Powershell Code: Finding Orphaned Group Policy Objects&#8221; &#8212; Metcorp Consulting Tech Blog\" src=\"http:\/\/blogs.metcorpconsulting.com\/tech\/?p=1076&#038;embed=true#?secret=nXOKTDzfht\" data-secret=\"nXOKTDzfht\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\r\n\r\nRelease 1.1\r\nModified by Jeremy@jhouseconsulting.com 29th August 2012\r\n\r\n#&gt;\r\n\r\n$Domain = &#x5B;System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()\r\n# Get AD Domain Name\r\n$DomainDNS = $Domain.Name\r\n# Get AD Distinguished Name\r\n$DomainDistinguishedName = $Domain.GetDirectoryEntry() | select -ExpandProperty DistinguishedName\r\n\r\n$GPOPoliciesDN = &quot;CN=Policies,CN=System,$DomainDistinguishedName&quot;\r\n$GPOPoliciesSYSVOLUNC = &quot;\\\\$DomainDNS\\SYSVOL\\$DomainDNS\\Policies&quot;\r\n\r\nWrite-Host -ForegroundColor Green &quot;Finding all orphaned Group Policy Objects (GPOs)...`n&quot;\r\n\r\nWrite-Host -ForegroundColor Green &quot;Reading GPO information from Active Directory ($GPOPoliciesDN)...&quot;\r\n$GPOPoliciesADSI = &#x5B;ADSI]&quot;LDAP:\/\/$GPOPoliciesDN&quot;\r\n&#x5B;array]$GPOPolicies = $GPOPoliciesADSI.psbase.children\r\nForEach ($GPO in $GPOPolicies) { &#x5B;array]$DomainGPOList += $GPO.Name }\r\n#$DomainGPOList = $DomainGPOList -replace(&quot;{&quot;,&quot;&quot;) ; $DomainGPOList = $DomainGPOList -replace(&quot;}&quot;,&quot;&quot;)\r\n$DomainGPOList = $DomainGPOList | sort-object\r\n&#x5B;int]$DomainGPOListCount = $DomainGPOList.Count\r\nWrite-Host -ForegroundColor Green &quot;Discovered $DomainGPOListCount GPCs (Group Policy Containers) in Active Directory ($GPOPoliciesDN)`n&quot;\r\n\r\nWrite-Host -ForegroundColor Green &quot;Reading GPO information from SYSVOL ($GPOPoliciesSYSVOLUNC)...&quot;\r\n&#x5B;array]$GPOPoliciesSYSVOL = Get-ChildItem $GPOPoliciesSYSVOLUNC\r\nForEach ($GPO in $GPOPoliciesSYSVOL) {If ($GPO.Name -ne &quot;PolicyDefinitions&quot;) {&#x5B;array]$SYSVOLGPOList += $GPO.Name }}\r\n#$SYSVOLGPOList = $SYSVOLGPOList -replace(&quot;{&quot;,&quot;&quot;) ; $SYSVOLGPOList = $SYSVOLGPOList -replace(&quot;}&quot;,&quot;&quot;)\r\n$SYSVOLGPOList = $SYSVOLGPOList | sort-object\r\n&#x5B;int]$SYSVOLGPOListCount = $SYSVOLGPOList.Count\r\nWrite-Host -ForegroundColor Green &quot;Discovered $SYSVOLGPOListCount GPTs (Group Policy Templates) in SYSVOL ($GPOPoliciesSYSVOLUNC)`n&quot;\r\n\r\n## COMPARE-OBJECT cmdlet note:\r\n## The =&gt; sign indicates that the item in question was found in the property set of the second object but not found in the property set for the first object.\r\n## The &lt;= sign indicates that the item in question was found in the property set of the first object but not found in the property set for the second object.\r\n\r\n# Check for GPTs in SYSVOL that don't exist in AD\r\n&#x5B;array]$MissingADGPOs = Compare-Object $SYSVOLGPOList $DomainGPOList -passThru | Where-Object { $_.SideIndicator -eq '&lt;=' }\r\n&#x5B;int]$MissingADGPOsCount = $MissingADGPOs.Count\r\n$MissingADGPOsPCTofTotal = $MissingADGPOsCount \/ $DomainGPOListCount\r\n$MissingADGPOsPCTofTotal = &quot;{0:p2}&quot; -f $MissingADGPOsPCTofTotal\r\nWrite-Host -ForegroundColor Yellow &quot;There are $MissingADGPOsCount GPTs in SYSVOL that don't exist in Active Directory ($MissingADGPOsPCTofTotal of the total)&quot;\r\nIf ($MissingADGPOsCount -gt 0 ) {\r\n Write-Host &quot;These are:&quot;\r\n $MissingADGPOs\r\n}\r\nWrite-Host &quot;`n&quot;\r\n\r\n# Check for GPCs in AD that don't exist in SYSVOL\r\n&#x5B;array]$MissingSYSVOLGPOs = Compare-Object $DomainGPOList $SYSVOLGPOList -passThru | Where-Object { $_.SideIndicator -eq '&lt;=' }\r\n&#x5B;int]$MissingSYSVOLGPOsCount = $MissingSYSVOLGPOs.Count\r\n$MissingSYSVOLGPOsPCTofTotal = $MissingSYSVOLGPOsCount \/ $DomainGPOListCount\r\n$MissingSYSVOLGPOsPCTofTotal = &quot;{0:p2}&quot; -f $MissingSYSVOLGPOsPCTofTotal\r\nWrite-Host -ForegroundColor Yellow &quot;There are $MissingSYSVOLGPOsCount GPCs in Active Directory that don't exist in SYSVOL ($MissingSYSVOLGPOsPCTofTotal of the total)&quot;\r\nIf ($MissingSYSVOLGPOsCount -gt 0 ) {\r\n Write-Host &quot;These are:&quot;\r\n $MissingSYSVOLGPOs\r\n}\r\nWrite-Host &quot;`n&quot;\r\n<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Group Policy Objects (GPOs) are stored in two parts: GPC (Group Policy Container). The GPC is where the GPO stores all the AD-related configuration under the\u00a0CN=Policies,CN=System,DC=&#8230; container, which is replicated via AD replication. GPT (Group Policy Templates). The GPT is where the GPO stores the actual settings located within SYSVOL\u00a0area under the Policies folder, which &#8230; <a title=\"Finding Orphaned Group Policy Objects\" class=\"read-more\" href=\"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/2012\/09\/03\/finding-orphaned-group-policy-objects-807\" aria-label=\"Read more about Finding Orphaned Group Policy Objects\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[202,60,5],"tags":[216,214,218,217,215,220,221],"class_list":["post-807","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-group-policy","category-scripting","tag-gpc","tag-gpo","tag-gpt","tag-group-policy-container","tag-group-policy-object","tag-group-policy-templates","tag-orphaned-gpo"],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/comments?post=807"}],"version-history":[{"count":28,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/807\/revisions"}],"predecessor-version":[{"id":830,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/posts\/807\/revisions\/830"}],"wp:attachment":[{"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/media?parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/categories?post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jhouseconsulting.com\/jhouseconsulting\/wp-json\/wp\/v2\/tags?post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}