Comments
4 comments
-
This is the problem that I found out while I was executing the script below.
Get-SQLClone function has different behaviour in OPTION 1 and OPTION 2
OPTION 2 raise an exception,
OPTION 1 noConnect-SqlClone -ServerUrl $ServerUrl#list available image related to $ImageName parameter
$images = Get-SqlCloneImage -Name $ImageName
#get the last image available$image = $images | Sort-Object -Property CreatedDate -Descending | Select-Object -First 1# get the sql clone sql server instance$sqlServerInstance = Get-SqlCloneSqlServerInstance -MachineName $MachineName
########################## OPTION 1 ################$clones = Get-SqlClone -Image $imageif (!($null -eq $clones)){"Will not remove image {0} because it has {1} dependent clone(s)." -f $image.Name, $clones.Count}else{"Will not remove image {0} because this is a test." -f $image.Name}##################################################
#####################OPTION 2 #########################try{$clones = Get-SqlClone -Name $DatabaseName -Location $SqlServerInstance}
catch {"ERROR::<< {0} >>" -f $error.Exception.Message# Write-Host $_Write-Output $error.Exception.Message# exit -1;}
##################################################
-
Hi,
Thank you for your forum post.
I am little confused by your post.
The purpose of the Get-SqlClone Cmdlet is to return a CloneResource that can then be used by the Remove-SqlClone cmdlet. So if the Clone does not exist, I would expect a message to be returned to indicate that it does not exist.
In the help documentation there is a worked example on refeshing clones to use an updated image, available here.
Many Thanks
Eddie -
Hi Eddie,
yes, exactly..it is what I would expect too, instead I receive an error.
I Don't understand why in the first case if I don't find a clone resource the cmdlet returns null, instead in the second case if I don't find a clone resource the cmdlet returns an error. -
I followed the instructions of the link you sent me and I changed the code in this way
$clones = Get-SqlClone | Where-Object { $_.Name -eq $DatabaseName -and $_.LocationId -eq $SqlServerInstance.Id }
Thank you, Eddie
Add comment
Please sign in to leave a comment.
Thanks