Is there a way to identify the oldest version of an image, based on the original database name?

RedgateRossRedgateRoss Posts: 5 New member
Hi Guys,

I am trying to accomplish the following via PowerShell.

In my enviroment I have multiple images of multiple databases (each Image has a different name).

I am looking for a method to easily identify the oldest version of each database images (using "OriginDatabaseName" in the Get-SqlCloneImage cmdlet to identify the original database). I have tried to identify these by using Get-SqlCloneImage, but I am having difficulty formulating the right approach.

I have hit a brick wall with this - my powershell skills are getting better, but I am not an expert. Any help with this would be greatly appreciated.

Thanks,




Answers

  • chris_godfreechris_godfree Posts: 50 Silver 1

    Hi RedgateRoss, here's some Powershell I use to find the most recent image for any given database:

    $allImages = Get-SqlCloneImage | Where-Object {$_.OriginDatabaseName -eq $database}

    $LatestImage = $allImages | Sort-Object -Property CreatedDate | Select-Object -Last 1

    $latestImageName = $latestImage.Name

    Chris


  • RedgateRossRedgateRoss Posts: 5 New member
    Thank you, Chris.

    A much more elgant mehtod than the one i came up with!

    I'm really impressed with the knowledge on these forums.

    Thanks again,
    Ross
Sign In or Register to comment.