Featured image of post Monitoring with PowerShell: VSS Snapshot size

Monitoring with PowerShell: VSS Snapshot size

We’ve been doing some work for another IT company of a friend of mine. I’ve been helping him with automation inside of his RMM system. He is like me and really likes to have VSS as a third or fourth backup solution, just for those small emergencies when a file is deleted.

The issue with this is that VSS snapshots can sometimes consume a lot of space. The default a VSS snapshot can consume is 10 percent of the entire disk. On larger disks such as file servers this can be hundreds of gigabytes. Instead of just lowering the quota I’ve decided to create a small monitor that can alert when a specific threshold has been reached and we can react on that. This way we can just let the VSS snapshot size be the 10% for all our clients, and only change the ones where we see it will consume a lot of disk space.

The script uses the cim/wmi instance “Win32_ShadowStorage to retrieve the correct sizes and compares it to the threshold.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$threshold = "600" #threshold in GB
$DiskSpaceUsed = Get-CimInstance -ClassName Win32_ShadowStorage | Select-Object @{n = "Used (GB)"; e = { [math]::Round([double]$_.UsedSpace / 1GB, 3) } }, @{n = "Max (GB)"; e = { [math]::Round([double]$_.MAxSpace / 1GB, 3) } }, *
$HealthState = foreach ($Disks in $DiskSpaceUsed) {

    $Volume = get-volume -UniqueId $DiskSpaceUsed.Volume.DeviceID
    $DiskSize = [math]::Round([double]$volume.Size / 1GB, 3)
    $diskremaining = [math]::Round([double]$volume.SizeRemaining / 1GB, 3)
    if ($Disks.'Used (GB)' -gt $threshold) { "Disk $($Volume.DriveLetter) snapshot size is higher than $Threshold. The disk size is $($diskSize) and it has $($diskremaining) remaining space. The max snapshot size is $($Disks.'Max (GB)')" }

}

if (!$HealthState) {
$HealthState = "Healthy"
}

And that’s it! a short but sweet one. As always, Happy PowerShelling!

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy