From bfe36f0d4f13ee6ab2b62d8d7075cf1f4f993150 Mon Sep 17 00:00:00 2001 From: NiceDevil Date: Tue, 19 Dec 2023 15:35:45 +0000 Subject: [PATCH] Add Windows/BackupGPO.ps1 --- Windows/BackupGPO.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Windows/BackupGPO.ps1 diff --git a/Windows/BackupGPO.ps1 b/Windows/BackupGPO.ps1 new file mode 100644 index 0000000..60d60b8 --- /dev/null +++ b/Windows/BackupGPO.ps1 @@ -0,0 +1,10 @@ +$limit = (Get-Date).AddDays(-30) +$path = "\\NETWORKSHARE" + +# Delete files older than the $limit. +Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force + +# Delete any empty directories left behind after deleting the old files. +Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse + +Backup-GPO -All -path $path -Comment "Backup done from SERVERNAME" \ No newline at end of file