diff --git a/Cleanup-SystemTempFiles.ps1 b/Cleanup-SystemTempFiles.ps1 index 63b7382..2d72c91 100644 --- a/Cleanup-SystemTempFiles.ps1 +++ b/Cleanup-SystemTempFiles.ps1 @@ -138,7 +138,7 @@ If ( Test-Path $ADSKInst ) { # Delete all but most recent shadow copy of system drive $SystemVolume = Get-CimInstance -ClassName Win32_Volume -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "${Env:SystemDrive}\" } -$ShadowCopies = Get-CimInstance -ClassName Win32_ShadowCopy | Where-Object { $_.VolumeName -like $SystemVolume.DeviceID } +$ShadowCopies = Get-CimInstance -ClassName Win32_ShadowCopy -ErrorAction SilentlyContinue | Where-Object { $_.VolumeName -like $SystemVolume.DeviceID } If ( $ShadowCopies.Count -gt 1 ) { Write-Output "Deleting all of the oldest shadow copies of ${Env:SystemDrive}" $ShadowsToDelete = $ShadowCopies.Count - 1