-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
889ce5f
commit 193ddd6
Showing
9 changed files
with
219 additions
and
59 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force | ||
|
||
Remove-GPOZaurrLegacyFiles -Verbose -BackupPath $Env:USERPROFILE\Desktop\BackupADM -BackupDated -RemoveEmptyFolders #-WhatIf #-LimitProcessing 2 -WhatIf | ||
Remove-GPOZaurrLegacyFiles -Verbose -BackupPath $Env:USERPROFILE\Desktop\BackupADM1 -BackupDated -RemoveEmptyFolders #-WhatIf #-LimitProcessing 2 -WhatIf |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force | ||
|
||
Get-GPOZaurrEmptyFolders | Where-Object { $_.Name -eq 'Adm' } | Format-Table * | ||
# Report on empty folders | ||
Get-GPOZaurrFolders -FolderType Empty | Format-Table * | ||
|
||
Remove-GPOZaurrEmptyFolders -Folders Adm -Verbose -LimitProcessing 1 | ||
# ! NOT READY FOR EMPTY | ||
#Remove-GPOZaurrFolders -FolderType Empty -Verbose -BackupPath $Env:USERPROFILE\Desktop\SomeBackup1 -WhatIf |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force | ||
|
||
# Report on NTFRS folders | ||
Get-GPOZaurrFolders -FolderType NTFRS | Format-Table * | ||
|
||
# Remove NTFRS (broken replication folders) | ||
Remove-GPOZaurrFolders -FolderType NTFRS -Verbose -BackupPath $Env:USERPROFILE\Desktop\SomeBackup -WhatIf |
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
function Get-GPOZaurrFolders { | ||
[cmdletBinding()] | ||
param( | ||
[ValidateSet('All', 'Netlogon', 'Sysvol')][string[]] $Type = 'All', | ||
[ValidateSet('All', 'NTFRS', 'Empty')][string] $FolderType = 'All', | ||
[alias('ForestName')][string] $Forest, | ||
[string[]] $ExcludeDomains, | ||
[alias('Domain', 'Domains')][string[]] $IncludeDomains, | ||
[System.Collections.IDictionary] $ExtendedForestInformation, | ||
[switch] $AsHashTable | ||
) | ||
$ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation | ||
foreach ($Domain in $ForestInformation.Domains) { | ||
$Path = @( | ||
if ($Type -contains 'All') { | ||
"\\$Domain\SYSVOL\$Domain" | ||
} | ||
if ($Type -contains 'Sysvol') { | ||
"\\$Domain\SYSVOL\$Domain\policies" | ||
} | ||
if ($Type -contains 'NetLogon') { | ||
"\\$Domain\NETLOGON" | ||
} | ||
) | ||
# Order does matter | ||
$Folders = [ordered] @{ | ||
"\\$Domain\SYSVOL\$Domain\policies\PolicyDefinitions" = @{ | ||
Name = 'SYSVOL PolicyDefinitions' | ||
} | ||
"\\$Domain\SYSVOL\$Domain\policies" = @{ | ||
Name = 'SYSVOL Policies' | ||
} | ||
"\\$Domain\SYSVOL\$Domain\scripts" = @{ | ||
Name = 'NETLOGON Scripts' | ||
} | ||
"\\$Domain\SYSVOL\$Domain\StarterGPOs" = @{ | ||
Name = 'SYSVOL GPO Starters' | ||
} | ||
"\\$Domain\NETLOGON" = @{ | ||
Name = 'NETLOGON Scripts' | ||
} | ||
"\\$Domain\SYSVOL\$Domain\DfsrPrivate" = @{ | ||
Name = 'DfsrPrivate' | ||
} | ||
"\\$Domain\SYSVOL\$Domain" = @{ | ||
Name = 'SYSVOL Root' | ||
} | ||
} | ||
$Exclusions = @{ | ||
DfsrPrivate = @{ | ||
ConflictAndDeleted = $true | ||
Deleted = $true | ||
Installing = $true | ||
} | ||
'SYSVOL Policies' = @{ | ||
User = $true | ||
Machine = $true | ||
} | ||
'NETLOGON Scripts' = @{ | ||
|
||
} | ||
'SYSVOL Root' = @{ | ||
|
||
} | ||
'SYSVOL GPO Starters' = @{ | ||
|
||
} | ||
'SYSVOL PolicyDefinitions' = @{ | ||
|
||
} | ||
} | ||
|
||
Get-ChildItem -Path $Path -ErrorAction SilentlyContinue -Recurse -ErrorVariable +err -Force -Directory | ForEach-Object { | ||
$FileType = foreach ($Key in $Folders.Keys) { | ||
if ($_.FullName -like "$Key*") { | ||
$Folders[$Key] | ||
break | ||
} | ||
} | ||
$RootFolder = $Folders["$($_.FullName)"] | ||
if ($RootFolder) { | ||
$IsRootFolder = $true | ||
} else { | ||
$IsRootFolder = $false | ||
} | ||
|
||
$IsExcluded = $Exclusions["$($FileType.Name)"]["$($_.Name)"] -is [bool] | ||
if ($IsRootFolder -and $IsExcluded -eq $false) { | ||
$IsExcluded = $true | ||
} | ||
|
||
$FullFolder = Test-Path -Path "$($_.FullName)\*" | ||
$BrokenReplicationRoot = $_.Name -like '*_NTFRS_*' | ||
$BrokenReplicationChild = $_.FullName -like '*_NTFRS_*' -and $_.Name -notlike '*_NTFRS_*' | ||
$BrokenReplication = $_.FullName -like '*_NTFRS_*' | ||
|
||
$Object = [ordered] @{ | ||
FolderType = $FileType.Name | ||
FullName = $_.FullName | ||
IsEmptyFolder = -not $FullFolder | ||
IsBrokenReplication = $BrokenReplication | ||
IsBrokenReplicationRoot = $BrokenReplicationRoot | ||
IsBrokenReplicationChild = $BrokenReplicationChild | ||
IsRootFolder = $IsRootFolder | ||
IsExcluded = $IsExcluded | ||
Name = $_.Name | ||
Root = $_.Root | ||
Parent = $_.Parent | ||
CreationTime = $_.CreationTime | ||
LastWriteTime = $_.LastWriteTime | ||
Attributes = $_.Attributes | ||
DomainName = $Domain | ||
} | ||
if (-not $Object.IsExcluded) { | ||
if ($FolderType -eq 'Empty' -and $Object.IsEmptyFolder -eq $true) { | ||
if ($AsHashTable) { | ||
$Object | ||
} else { | ||
[PSCustomObject] $Object | ||
} | ||
} elseif ($FolderType -eq 'NTFRS' -and $Object.IsBrokenReplicationRoot -eq $true) { | ||
if ($AsHashTable) { | ||
$Object | ||
} else { | ||
[PSCustomObject] $Object | ||
} | ||
} elseif ($FolderType -eq 'All') { | ||
if ($AsHashTable) { | ||
$Object | ||
} else { | ||
[PSCustomObject] $Object | ||
} | ||
} | ||
} | ||
} | ||
} | ||
foreach ($e in $err) { | ||
Write-Warning "Get-GPOZaurrFolders - $($e.Exception.Message) ($($e.CategoryInfo.Reason))" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
function Remove-GPOZaurrFolders { | ||
[cmdletBinding(SupportsShouldProcess)] | ||
param( | ||
[string] $BackupPath, | ||
[switch] $BackupDated, | ||
[ValidateSet('All', 'Netlogon', 'Sysvol')][string[]] $Type = 'All', | ||
[Parameter(Mandatory)][ValidateSet('NTFRS', 'Empty')][string] $FolderType, | ||
[string[]] $FolderName, | ||
[int] $LimitProcessing = [int32]::MaxValue, | ||
[alias('ForestName')][string] $Forest, | ||
[string[]] $ExcludeDomains, | ||
[alias('Domain', 'Domains')][string[]] $IncludeDomains, | ||
[System.Collections.IDictionary] $ExtendedForestInformation | ||
) | ||
if ($BackupPath) { | ||
if ($BackupDated) { | ||
$BackupFinalPath = "$BackupPath\$((Get-Date).ToString('yyyy-MM-dd_HH_mm_ss'))" | ||
} else { | ||
$BackupFinalPath = $BackupPath | ||
} | ||
} else { | ||
$BackupFinalPath = '' | ||
} | ||
|
||
Get-GPOZaurrFolders -Type $Type -FolderType $FolderType -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation | Where-Object { | ||
if ($FolderName) { | ||
foreach ($Folder in $FolderName) { | ||
if ($_.Name -eq $Folder) { | ||
$_ | ||
} | ||
} | ||
} else { | ||
$_ | ||
} | ||
} | Select-Object | Select-Object -First $LimitProcessing | ForEach-Object { | ||
if ($BackupFinalPath) { | ||
$SYSVOLRoot = "\\$($_.DomainName)\SYSVOL\$($_.DomainName)\" | ||
$DestinationFile = ($_.FullName).Replace($SYSVOLRoot, '') | ||
#$DestinationMissingFolder = $DestinationFile.Replace($DestinationFile, '') | ||
$DestinationFilePath = [system.io.path]::Combine($BackupFinalPath, $DestinationFile) | ||
#$DestinationFolderPath = [system.io.path]::Combine($BackupFinalPath, $DestinationMissingFolder) | ||
|
||
Write-Verbose "Remove-GPOZaurrFolders - Backing up $($_.FullName)" | ||
Try { | ||
Copy-Item -LiteralPath $_.FullName -Recurse -Destination $DestinationFilePath -ErrorAction Stop -Force | ||
$BackupWorked = $true | ||
} catch { | ||
Write-Warning "Remove-GPOZaurrFolders - Error backing up error: $($_.Exception.Message)" | ||
$BackupWorked = $false | ||
} | ||
|
||
} | ||
if ($BackupWorked -or $BackupFinalPath -eq '') { | ||
try { | ||
Write-Verbose "Remove-GPOZaurrFolders - Removing $($_.FullName)" | ||
Remove-Item -Path $_.FullName -Force -Recurse | ||
} catch { | ||
Write-Warning "Remove-GPOZaurrFolders - Failed to remove directory $($_.FullName): $($_.Exception.Message)." | ||
} | ||
} | ||
} | ||
} |