1. Change the TargetPath
2. Copy the script in SSMS
3. Run it
SQl Hunt,
2019-05-03 (first published: 2015-07-30)
1. Change the TargetPath
2. Copy the script in SSMS
3. Run it
--Script to delete the old files & Folders Older than 30 days DECLARE @pscmd varchar(1000) DECLARE @targetpath varchar(8000) DECLARE @olddays int DECLARE @extension varchar(5) DECLARE @cmdstring varchar(1000) SET @targetpath = 'D:\SQLBackup\'; SET @olddays = -30 --pass the days with negative values --SET @extension = 'txt'; --/csv SET @pscmd = '"& '+ 'Get-ChildItem ' + Quotename(@targetpath,'''') + '-Recurse' + ' | '+ 'where {$_.lastWriteTime -lt ((Get-Date).AddDays('+ CAST(@olddays as varchar) +')) '+ --'-and ($_.Extension -match ' + QUOTENAME(@extension,'''')+ ') } | ' + --'-and ($_.Extension -match ' + ') } | ' + '} |' + 'Remove-Item -force " ' SET @cmdstring = ' ""powershell.exe" '+ @pscmd select @cmdstring exec master..xp_cmdshell @cmdstring, no_output
You rated this post out of 5. Change rating
This script is to verify which login accounts have SID values that don’t match the correct SID values defined on the machine or in the domain.
2019-05-03 (first published: 2014-12-24)
1,574 reads
Remove backup folders from multiple servers.
2019-05-03 (first published: 2014-12-09)
575 reads
If you want to extract only deadlock details, use the script.
2019-05-03 (first published: 2014-12-03)
3,649 reads
If you want to read trace file records from default trace location and want to print to see what are all the activities happened on SQL Server, the query will be helpful for you.
2019-05-03 (first published: 2014-11-12)
1,703 reads
Extract SQL Server Name, Instance Name, Service Account details, startMode and ServiceState details with Powershell.
2019-05-03 (first published: 2014-10-13)
4,885 reads