about backup

This topic contains 3 replies, has 2 voices, and was last updated by Avatar Anonymous 1 year, 12 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Avatar


    We are using windows server backup in build functionality for our server and we have connected 1 TB USB External drive with server.

    Now the drive is getting full after every few days, so i am deleting the shadow copy one by one by following command

    List shadows all
    delete shadows id xxxx

    Now I want to delete the oldest shadow copy automatically after every 20 days..so is is possible using the powershell script..



    A quick search using our best buddy :google:, and found this MS article with a script included. Modify to suit your conditions:



    Hi Rickless,

    Thanks for your quick reply,

    I have applied the scripts on my server. I am having 12 windows server backup copies and I have edit the scripts as below and make a change that any backup older than the 5 days, should be deleted..but its not deleting …

    What could be the reason…


    #PowerShell Script
    #This script deletes all shadow copies older than 5 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 5 -and $strClientAccessible -eq “True”) {



    please help…



    I don’t have access to a PC with Shadow Copies enabled so can’t test your code myself, but I’d say your final ‘If’ is the problem. The New-Timespan command doesn’t give you just a string, it appears to give you a datetime object. So your math to subtract the 2 values doesn’t result in just the # of days difference, it gives year/month/day/minute/second/etc. You’ve got to pick out just the date info, and then compare the values to see the difference, to be more than 5 days as opposed to 5 hours or 5 years.

    If you step thru the code one line at a time and hover over the variables you’ve used after each line has executed, you’ll see the values in each. That way you can identify whether your declarations and formats give you the data you want.

    Since Powershell works with this data format natively, you might want to simplify your logic a bit. Get-Date gives you the current datetime; you can create a value 5 days older than current by simply adding a negative 5 (-5) days to the current value and assign it to a variable, like this: $limit = (Get-Date).AddDays(-5). Then simply see if the $_.InstallDate is less than your $limit variable, and delete if it is.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.