PoshCode Archive  Artifact [82ebfef12c]

Artifact 82ebfef12cbdff1751cd518ae9593f4e42496922bb3669d884681a7e0511aecf:

  • File Delete-Old-Shadow-Copies.ps1 — part of check-in [a09f029b70] at 2018-06-10 13:45:17 on branch trunk — 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. (user: Wayne Johnson size: 970)

# 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()
}

}