Last active
May 24, 2017 14:00
-
-
Save PixelRobots/e603be054e1ff7b60c0e687d4428b0f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.SYNOPSIS | |
Script used to find all unlinked gpos, back them up and then delete them. | |
.DESCRIPTION | |
The script searches your logged on domain for unlinked GPO's. It then backs them up to a folder on the C:\. It will then remove them. It also creates a log file in the same directory. | |
.LINK | |
http://www.pixelrobots.com | |
#> | |
Import-Module grouppolicy | |
$domain = get-addomain | |
$DNS = $domain.DNSRoot | |
$path= "C:\GPOBackups" | |
New-Item $Path -type directory -Force | |
Get-GPO -All -DomainName $DNS | Sort-Object displayname | Where-Object { If ( $_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "<LinksTo>" ) | |
{ | |
$name = $_.DisplayName | |
$dir = New-Item "$path\$DNS\$name" -Type Directory | |
Backup-GPO -Guid $_.Id -Path $dir | |
Get-GPOReport -name $name -ReportType Html -Path "$dir\$name.html" | |
$_.DisplayName | Out-File "$path\$DNS\UnLinkedGPOS.txt" -Append | |
$_.Displayname | remove-gpo -Confirm -WhatIf | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment