Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Using the -Image parameter of Get-SqlClone

...

Code Block
languagepowershell
themeConfluence
Connect-SqlClone -ServerUrl 'http://sql-clone.example.com:14145'

$imageTimeToLiveDays = 7;

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

foreach ($image in $oldImages)
{
    $clones = Get-SqlClone | Where-Object {$_.ParentImageId -eq $image.Id}Image $image
    
    if (!($clones -eq $null))
    {
        "Will not remove image {0} because it has {1} dependent clone(s)." -f $image.Name, $clones.Count
    }
    else
    {
        Remove-SqlCloneImage -Image $image
        "Removed image {0}." -f $image.Name
    }
}