Created
April 29, 2015 23:43
-
-
Save bill-long/631f64dc0bacc9d6974f to your computer and use it in GitHub Desktop.
PurgeOldPerfmons.ps1. Attach this to a scheduled task that runs the perfmon. An alternative to fighting with Data Manager settings.
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" | |
$numberOfDirectoriesToKeep = 3 | |
# Check to see if we need to clean up old nmcap files | |
$directories = new-object 'System.Collections.Generic.List[string]' | |
$directories.AddRange([System.IO.Directory]::GetDirectories($perfLogsFolder)) | |
while ($directories.Count -gt $numberOfDirectoriesToKeep) | |
{ | |
$oldestFileTime = [DateTime]::MaxValue | |
$oldestFileName = "" | |
foreach ($directory in $directories) | |
{ | |
$fileTime = [System.IO.Directory]::GetCreationTime($directory) | |
if ($fileTime -lt $oldestFileTime) | |
{ | |
$oldestFileTime = $fileTime | |
$oldestDirectoryName = $directory | |
} | |
} | |
[System.IO.Directory]::Delete($oldestDirectoryName, $true) | |
$directories.Remove($oldestDirectoryName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment