forked from samyan19/SQL-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteBackups.ps1
More file actions
14 lines (10 loc) · 824 Bytes
/
DeleteBackups.ps1
File metadata and controls
14 lines (10 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
Param([int] $numDays, [string] $BackupDir, [string] $FileExtensionToDelete)
##################################################################################################################################################
#Example values for Variables for the file
#
#$numDays = 2 (days worth of files to keep)
#$BackupDir = "Z:\MSSQL\RCSTVSQL2K53-02\9.00\01_ISQL2K502\BACKUPS\FULL\*" (Location of the files needed deleting (* searches all subdirs)
#$FileExtensionToDelete = "bak" (kinda files to delete)
###################################################################################################################################################
$date = (Get-Date).Adddays(- $numDays)
Get-ChildItem $BackupDir -include *.$FileExtensionToDelete -recurse | Where-Object {$_.LastWriteTime -lt $date} | Remove-Item