User Tools

Site Tools


unlinked_gpos

This is an old revision of the document!


Remover los GPOs sin linkear

<#
.SYNOPSIS Backup and Remove unlinked GPOs
#>

Import-Module GroupPolicy
$Date = Get-Date -Format dd_MM_yyyy
$BackupPath = "C:\temp\GPOBackup\$Date"
if (-Not(Test-Path -Path $BackupPath)) 
{ New-Item -ItemType Directory $BackupPath -Force}
Get-GPO -All | Sort-Object displayname | Where-Object { If ( $_ | Get-GPOReport -ReportType XML | Select-String -NotMatch "<LinksTo>" )
 {
   Backup-GPO -Name $_.DisplayName -Path $BackupPath
   Get-GPOReport -Name $_.DisplayName -ReportType Html -Path "c:\admin\GPOBackup\$Date\$($_.DisplayName).html"
   $_.DisplayName | Out-File "C:\temp\GPOBackup\$Date\UnlinkedGPOs.txt" -Append
   $_.Displayname | remove-gpo -Confirm
 }
}
unlinked_gpos.1605478473.txt.gz · Last modified: 2024/10/17 21:42 (external edit)