Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean up Azure Fabric Perfmon Logs
Function Clear-S4BFabricLogs
{
<#
.SYNOPSIS
Removes old Windows Fabric log files and Perfmon Data
.DESCRIPTION
Removes logfiles older than 14 days from the following locations
C:\ProgramData\Microsoft\SF\Log\PerformanceCounters_WindowsFabricPerfCounter
C:\ProgramData\Microsoft\SF\Log\PerformanceCountersBinaryArchive
.EXAMPLE
Clear-S4BFabricLogs
Removes the logs
.LINK
http://www.UcMadScientist.com
.INPUTS
This function does not accept pipelined input
.OUTPUTS
This function does not create pipelined output
#>
[CmdletBinding()]
$function = 'Clear-S4BFabricLogs'
$SpaceBefore = (Get-WmiObject -Class Win32_logicaldisk -Filter "DeviceID = 'C:'" | Select-Object -Property @{L='FreeSpaceGB';E={"{0:N2}" -f ($_.FreeSpace /1GB)}})
Write-Host "Cleaning up files"
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays(-14)
$FolderstoClean = @(
"C:\ProgramData\Microsoft\SF\Log\PerformanceCountersBinaryArchive"
"C:\ProgramData\Microsoft\SF\Log\PerformanceCounters_WindowsFabricPerfCounter"
)
ForEach ($folder in $FolderstoClean) {
Write-Host "Checking $Folder"
$files = (Get-ChildItem $Folder | Where-Object { $_.LastWriteTime -lt $DatetoDelete })
Write-Host "Found $($Files.Count) in $Folder"
Write-Host "Removing Files"
Get-ChildItem $Folder | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item
}
$SpaceAfter = (Get-WmiObject -Class Win32_logicaldisk -Filter "DeviceID = 'C:'" | Select-Object -Property @{L='FreeSpaceGB';E={"{0:N2}" -f ($_.FreeSpace /1GB)}})
$SpaceSaved = (($Spacebefore.FreeSpaceGB - $SpaceAfter.FreeSpaceGB) - ($Spacebefore.FreeSpaceGB - $SpaceAfter.FreeSpaceGB)*2)
Write-Host "Saved $SpaceSaved GB"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment