Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clean up Azure Fabric Perfmon Logs
Function Clear-S4BFabricLogs
Removes old Windows Fabric log files and Perfmon Data
Removes logfiles older than 14 days from the following locations
Removes the logs
This function does not accept pipelined input
This function does not create pipelined output
$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 = @(
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