Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created April 29, 2015 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/631f64dc0bacc9d6974f to your computer and use it in GitHub Desktop.
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.
$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