# encoding: ascii
# api: powershell
# title: Delete Old Shadow Copies
# description: I use this script to delete shadow copies older than 30 days from our file and print servers. I have it installed on Server 2012 Core Servers.
# version: 0.1
# type: script
# author: Wayne Johnson
# license: CC0
# x-poshcode-id: 4741
# x-archived: 2016-10-18T11:28:01
# x-published: 2016-12-26T22:36:00
#
#
#PowerShell Script
#This script deletes all shadow copies older than 30 days
#By Wayne Johnson
Get-WmiObject Win32_Shadowcopy | ForEach-Object {
$WmiSnapShotDate = $_.InstallDate
$strShadowID = $_.ID
$dtmSnapShotDate = [management.managementDateTimeConverter]::ToDateTime($WmiSnapShotDate)
$strClientAccessible = $_.ClientAccessible
$dtmCurDate = Get-Date
$dtmTimeSpan = New-TimeSpan $dtmSnapShotDate $dtmCurDate
$intNumberDays = $dtmTimeSpan.Days
If ($intNumberDays -ge 31 -and $strClientAccessible -eq "True") {
$_.Delete()
}
}