Created
April 30, 2015 00:03
-
-
Save bill-long/50f407f10ce474297211 to your computer and use it in GitHub Desktop.
PurgeOldPerfmons - individual file version
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
$perfLogsFolder = "C:\Perflogs" | |
$numberOfDaysToKeep = 3 | |
$dateThreshold = [DateTime]::Now.AddDays(0 - $numberOfDaysToKeep) | |
# Check to see if we need to clean up old nmcap files | |
$files = new-object 'System.Collections.Generic.List[string]' | |
$files.AddRange([System.IO.Directory]::GetFiles($perfLogsFolder)) | |
$filesToDelete = new-object 'System.Collections.Generic.List[string]' | |
foreach ($file in $files) | |
{ | |
$fileTime = [System.IO.File]::GetCreationTime($file) | |
if ($fileTime -lt $dateThreshold) | |
{ | |
$filesToDelete.Add($file) | |
} | |
} | |
foreach ($file in $filesToDelete) | |
{ | |
[System.IO.File]::Delete($file) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment