Skip to content

Instantly share code, notes, and snippets.

@belotn
Last active December 24, 2015 21:49
Show Gist options
  • Save belotn/6867957 to your computer and use it in GitHub Desktop.
Save belotn/6867957 to your computer and use it in GitHub Desktop.
Desactivate GPO Parts without settings
Get-ADOrganizationalUnit -Filter 'OU -like "*Citrix*"' -SearchBase 'dc=fabrikam,dc=com' -Properties * |% {
$_.gpLink -split ']' } |? {
$_ -match '[0,2]$'} |% {
(($_ -replace '\[','').split(';')[0]) -replace 'LDAP://',''} |% {
get-adobject $_ -properties * } |
sort -Unique DisplayName |% {
if( $_.Flags -ne 3 ){
if([bool]( gci "$($_.gPCFileSysPath)\User") -eq $false){
if([bool](gci "$($_.gPCFileSysPath)\Machine") -eq $false){
(get-gpo -Name $_.DisplayName).GpoStatus = "AllSettingsDisabled"
}else{
(get-gpo -Name $_.DisplayName).GpoStatus = "UserSettingsDisabled"
}
}else {
if([bool](gci "$($_.gPCFileSysPath)\Machine") -eq $false){
(get-gpo -Name $_.DisplayName).GpoStatus = "ComputerSettingsDisabled"
}ELSE{
#do nothing
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment