Determine VSS snapshots on servers

I always had the problem that VSS snapshots on servers were not cleaned up. At some point, the hard disk would fill up because the operating systems had countless snapshots that were never cleaned up. I therefore created a small script that determines the number of active snapshots and the date of the first and last snapshot.

$serverlist = @("SRV01″, "SRV02″, "SRV03″, "SRV04″, "USW")

$vssresults =@()
foreach ($server in $serverlist)
{
$vsslist = Get-WmiObject Win32_ShadowCopy -ComputerName $server
$vsscount = $vsslist.count
if ($vsscount -gt 0)
{
$oldestvss = $vsslist | select -first 1
$oldestvss = $oldestvss.Installdate
$oldestvss = $oldestvss.split(".")[0]
$oldestvss = [datetime]::ParseExact($oldestvss, "yyyyMMddHHmmss",$null)

$newestvss = $vsslist | select -last 1
$newestvss = $newestvss.Installdate
$newestvss = $newestvss.split(".")[0]
$newestvss = [datetime]::ParseExact($newestvss, "yyyyMMddHHmmss",$null)

$vssresults += new-object PSObject -property @{Servername="$server";SnapshotCount="$vsscount";OldestSnapshot="$oldestvss";NewestSnapshot="$newestvss"}
}
else
{
$vssresults += new-object PSObject -property @{Servername="$server";SnapshotCount="0″;OldestSnapshot="0″;NewestSnapshot="0″}
}
}

$vssresults

The "$vssresults" object receives all servers from "$serverlist" that have active snapshots. The object can then be further processed in order to integrate it into a monitoring solution such as Solarwinds or PRTG.

Leave a Comment