Last active
May 10, 2023 16:09
-
-
Save FlorianHeigl/da66e02edab336a5e82599383769b35a to your computer and use it in GitHub Desktop.
powershell delete vss snapshots via wmi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://github.com/MSAdministrator/PoshCodeMarkDown/blob/master/docs/Delete-Old-Shadow-Copies.ps1.md | |
# modified... | |
# TODO: only handle c: | |
# TODO: Never delete the last snapshot, or even better the last two? | |
Get-WmiObject Win32_Shadowcopy | ForEach-Object { | |
.InstallDate $strShadowID = $.ID $dtmSnapShotDate = [management.managementDateTimeConverter]::ToDateTime($WmiSnapShotDate) $strClientAccessible = $_.ClientAccessible $dtmCurDate = Get-Date | |
$dtmTimeSpan = New-TimeSpan $dtmSnapShotDate $dtmCurDate $intNumberDays = $dtmTimeSpan.Days | |
If ($intNumberDays -ge 7 -and $strClientAccessible -eq "True") { | |
$_.Delete() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://serverfault.com/a/527384/106483 looks better, especially
$shadowCopies[0].Delete()
- Deletes the first shadow copy when more than one exists