Is there a way to identify the oldest version of an image, based on the original database name?
RedgateRoss
Posts: 5 New member
in SQL Clone
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
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