These pages cover SQL Clone 1, which is not the latest version. Help for other versions is also available.

Skip to end of metadata
Go to start of metadata

If you are regularly creating images on a schedule, you may wish to clear out the older ones. This script will remove images older than a given date, as long as they don't have clone databases dependent on them (in which case warn in the output).

This script will remove images without any further warning. You will need to test this and add protections appropriate to your environment before live use.

Connect-SqlClone -ServerUrl ''

$imageTimeToLiveDays = 7;

$oldImages = Get-SqlCloneImage | Where-Object {$_.CreatedDate -le (Get-Date).AddDays(0-$imageTimeToLiveDays)}

foreach ($image in $oldImages)
    $clones = Get-SqlClone -Image $image
    if (!($clones -eq $null))
        "Will not remove image {0} because it has {1} dependent clone(s)." -f $image.Name, $clones.Count
        Remove-SqlCloneImage -Image $image
        "Removed image {0}." -f $image.Name
  • No labels