<#Created By - Abhishek Bansal
Read Me !!
Script Usage - This script will compare sub folder of Policies folder inside Sysvol for every DC with the Group Policy configured in GPMC
Once it compares, it will list all the Policy folders which are mapped to GPMC and show as "Valid GPO Folder" and Policy folder for any non existing Group Policy would be shows as "Not valid GPO folder .#>
$gpoid = Get-GPO -All
$dcs = (Get-ADDomainController -Filter *).Name
foreach($dc in $dcs)
{
if($(Test-Path -Path "\\$dc\sysvol\Mari.com\Policies")-eq $true)
{
$Sysvolgpos = $(Get-ChildItem -Path "\\$dc\sysvol\Mari.com\Policies" -Exclude "*PolicyDefin*").Name
$arr = @()
foreach($Sysvolgpo in $Sysvolgpos)
{
foreach($gpo in $gpoid)
{
$gpoingpmc = "{$($gpo.id)}"
if($($gpoingpmc -eq $Sysvolgpo))
{
$arr += $gpoingpmc
break
}
}
}
}
$Sysvolgpos | Where {$arr -Contains $_} | Select-Object -Property @{n="Domain Controller";e={$dc}},@{n="GPO Folder";e={$_}},@{n="Status";e={"Valid GPO folder"}}
$Sysvolgpos | Where {$arr -NotContains $_} | Select-Object -Property @{n="Domain Controller";e={$dc}},@{n="GPO Folder";e={$_}},@{n="Status";e={"Not valid GPO folder"}}
}
Sample Output