# This script can be used with SolarWinds SAM to monitor for rate of growth for a specific file
# Globally used variables
$FileToMonitor = "C:\Temp\FileToMonitor.txt"
$CacheFile = "C:\Temp\Cache.txt"
# Get Current file size
$FileSize = Get-Item -Path $FileToMonitor | Select-Object -ExpandProperty Length
# Write current file size to a cache file
Add-Content $CacheFile $FileSize
# Calculate the percent difference and round it to a whole number
$oldValue = Get-Content $CacheFile -First 1
$newValue = Get-Content $CacheFile -Last 1
$percentageDifference = (($newValue - $oldValue) / $oldValue) * 100
$percentageDifference = ([Math]::Round($percentageDifference, 0))
# Write to the host for SolarWinds to ingest
Write-Host "Message: File growth was calculated as $percentageDifference%"
Write-Host "Statistic:" $percentageDifference
# Keep the cache file clean/small (litterally just keeping 2-lines)
(Get-Content "$CacheFile" -Tail 2) | Set-Content "$CacheFile"
# Exit Session
Exit 0;