diff --git a/Examples/Example-21-ListLegacyADMFiles.ps1 b/Examples/Example-21-ListLegacyADMFiles.ps1 new file mode 100644 index 0000000..a7ef9ef --- /dev/null +++ b/Examples/Example-21-ListLegacyADMFiles.ps1 @@ -0,0 +1,3 @@ +Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force + +Get-GPOZaurrLegacyFiles | Format-Table -AutoSize \ No newline at end of file diff --git a/Examples/Example-22-RemoveLegacyADMFiles.ps1 b/Examples/Example-22-RemoveLegacyADMFiles.ps1 new file mode 100644 index 0000000..2db82bc --- /dev/null +++ b/Examples/Example-22-RemoveLegacyADMFiles.ps1 @@ -0,0 +1,3 @@ +Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force + +Remove-GPOZaurrLegacyFiles -Verbose -WhatIf \ No newline at end of file diff --git a/GPOZaurr.psd1 b/GPOZaurr.psd1 index 78c4264..c125f8f 100644 --- a/GPOZaurr.psd1 +++ b/GPOZaurr.psd1 @@ -5,7 +5,7 @@ CompatiblePSEditions = 'Desktop' Copyright = '(c) 2011 - 2020 Przemyslaw Klys @ Evotec. All rights reserved.' Description = 'Group Policy Eater' - FunctionsToExport = 'Add-GPOPermission', 'Add-GPOZaurrPermission', 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrAD', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrLink', 'Get-GPOZaurrOwner', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermission', 'Get-GPOZaurrPermissionConsistency', 'Get-GPOZaurrSysvol', 'Get-WMIFilter', 'Get-GPOZaurrWMI', 'Invoke-GPOZaurrPermission', 'New-GPOZaurrWMI', 'Remove-GPOPermission', 'Remove-GPOZaurr', 'Remove-GPOZaurrOrphanedSysvolFolders', 'Remove-GPOZaurrPermission', 'Remove-GPOZaurrWMI', 'Repair-GPOZaurrPermissionConsistency', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles', 'Set-GPOOwner', 'Set-GPOZaurrOwner' + FunctionsToExport = 'Add-GPOPermission', 'Add-GPOZaurrPermission', 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrAD', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrLegacyFiles', 'Get-GPOZaurrLink', 'Get-GPOZaurrOwner', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermission', 'Get-GPOZaurrPermissionConsistency', 'Get-GPOZaurrSysvol', 'Get-WMIFilter', 'Get-GPOZaurrWMI', 'Invoke-GPOZaurrPermission', 'New-GPOZaurrWMI', 'Remove-GPOPermission', 'Remove-GPOZaurr', 'Remove-GPOZaurrLegacyFiles', 'Remove-GPOZaurrOrphanedSysvolFolders', 'Remove-GPOZaurrPermission', 'Remove-GPOZaurrWMI', 'Repair-GPOZaurrPermissionConsistency', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles', 'Set-GPOOwner', 'Set-GPOZaurrOwner' GUID = 'f7d4c9e4-0298-4f51-ad77-e8e3febebbde' ModuleVersion = '0.0.32' PowerShellVersion = '5.1' @@ -17,7 +17,7 @@ } } RequiredModules = @{ - ModuleVersion = '0.0.144' + ModuleVersion = '0.0.145' ModuleName = 'PSSharedGoods' Guid = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe' }, @{ diff --git a/Public/Get-GPOZaurrLegacyFiles.ps1 b/Public/Get-GPOZaurrLegacyFiles.ps1 new file mode 100644 index 0000000..7abca8d --- /dev/null +++ b/Public/Get-GPOZaurrLegacyFiles.ps1 @@ -0,0 +1,16 @@ +function Get-GPOZaurrLegacyFiles { + [cmdletbinding()] + param( + [alias('ForestName')][string] $Forest, + [string[]] $ExcludeDomains, + [alias('Domain', 'Domains')][string[]] $IncludeDomains, + [System.Collections.IDictionary] $ExtendedForestInformation + ) + $ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation + foreach ($Domain in $ForestInformation.Domains) { + Get-ChildItem -Path "\\$Domain\SYSVOL\$Domain\policies" -ErrorAction SilentlyContinue -Recurse -Include '*.adm' -ErrorVariable err | Select-Object Name, FullName, CreationTime, LastWriteTime, Attributes + foreach ($e in $err) { + Write-Warning "Get-GPOZaurrLegacy - $($e.Exception.Message) ($($e.CategoryInfo.Reason))" + } + } +} \ No newline at end of file diff --git a/Public/Remove-GPOZaurrLegacyFiles.ps1 b/Public/Remove-GPOZaurrLegacyFiles.ps1 new file mode 100644 index 0000000..46eb50a --- /dev/null +++ b/Public/Remove-GPOZaurrLegacyFiles.ps1 @@ -0,0 +1,25 @@ +function Remove-GPOZaurrLegacyFiles { + [cmdletBinding(SupportsShouldProcess)] + param( + [alias('ForestName')][string] $Forest, + [string[]] $ExcludeDomains, + [alias('Domain', 'Domains')][string[]] $IncludeDomains, + + [int] $LimitProcessing = [int32]::MaxValue + ) + $Splat = @{ + Forest = $Forest + IncludeDomains = $IncludeDomains + ExcludeDomains = $ExcludeDomains + ExtendedForestInformation = $ExtendedForestInformation + Verbose = $VerbosePreference + } + Get-GPOZaurrLegacyFiles @Splat | Select-Object -First $LimitProcessing | ForEach-Object { + try { + Remove-Item -Path $_.FullName -ErrorAction Stop + } catch { + $ErrorMessage = $_.Exception.Message + Write-Warning "Remove-GPOZaurrLegacyFiles - Failed to remove file $($_.FullName): $($ErrorMessage)." + } + } +} \ No newline at end of file