Last active
July 6, 2022 02:16
-
-
Save Atreidae/8ef73e71570757a2ffb6dcfd21c0e18f to your computer and use it in GitHub Desktop.
Clean up Azure Fabric Perfmon Logs
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
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" | |
"C:\ProgramData\Microsoft\SF\Log\PerformanceCountersBinary" | |
) | |
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