I modified a Powershell script posted by austinmartinez2 at Spiceworks Sort ShadowCopies by Volume so that I could determine which drives have System Restore enabled.
I tried to make the output appear the way the information is presented in the control panel. Tested in Windows 7 SP1 and Windows 10 1809.
# Sort ShadowCopies by Volume
# https://community.spiceworks.com/topic/2155972-sort-shadowcopies-by-volume
# Original by austinmartinez2 Spiceworks
$shadowStorageList = @();
$volumeList = Get-WmiObject Win32_Volume -Property DriveLetter,DeviceID,Capacity,FreeSpace -Filter "DriveType=3 and FileSystem='NTFS'" | select @{n="DriveLetter";e={$_.DriveLetter.ToUpper()}},DeviceID,@{n="CapacityGB";e={([math]::Round([int64]($_.Capacity)/1GB,2))}},@{n="FreeSpaceGB";e={([math]::Round([int64]($_.FreeSpace)/1GB,2))}} | Sort DriveLetter;
$shadowStorages = gwmi Win32_ShadowStorage -Property AllocatedSpace,DiffVolume,MaxSpace,UsedSpace,Volume |
Select @{n="Volume";e={$_.Volume.Replace("\\","\").Replace("Win32_Volume.DeviceID=","").Replace("`"","")}},
@{n="DiffVolume";e={$_.DiffVolume.Replace("\\","\").Replace("Win32_Volume.DeviceID=","").Replace("`"","")}},
@{n="AllocatedSpaceGB";e={([math]::Round([int64]($_.AllocatedSpace)/1GB,2))}},
@{n="MaxSpaceGB";e={([math]::Round([int64]($_.MaxSpace)/1GB,2))}},
@{n="UsedSpaceGB";e={([math]::Round([int64]($_.UsedSpace)/1GB,2))}}
$volumeList | Where-Object {$_.DriveLetter -ne $Null} | ForEach-Object {
$DeviceID = $_.DeviceID
$DriveLetter = $_.DriveLetter
$DriveCapacityGB = $_.CapacityGB
$Protection = "Off"
#$AllocatedSpaceGB = ""
$UsedSpaceGB = ""
$MaxSpaceGB = ""
$MaxSpacePercent = ""
foreach ($shStorage in $shadowStorages) {
if ($shStorage.Volume -eq $DeviceID) {
$Protection = "On"
#$AllocatedSpaceGB = $shStorage.AllocatedSpaceGB
$UsedSpaceGB = $shStorage.UsedSpaceGB
$MaxSpaceGB = $shStorage.MaxSpaceGB
$MaxSpacePercent = "{0:P0}" -f ($MaxSpaceGB / $DriveCapacityGB)
}
}
$objVolume = New-Object PSObject -Property @{
DriveLetter = $DriveLetter
Protection = $Protection
#AllocatedSpaceGB = $AllocatedSpaceGB
UsedSpaceGB = $UsedSpaceGB
MaxSpaceGB = $MaxSpaceGB
MaxSpacePercent = $MaxSpacePercent
}
$shadowStorageList += $objVolume;
}
$shadowStorageList | Select DriveLetter, Protection, UsedSpaceGB, MaxSpaceGB, MaxSpacePercent
Comments