How to get clone location from Get-SqlClone

Is there any way to identify which server a clone sits on using the PowerShell cmdlets?
I was expecting Get-SqlClone to return the server name. I can't currently see any way of tying the outputs of Get-SqlClone and Get-SqlCloneSqlServerInstance together.
Tagged:

Best Answer

  • ErdoganOzkocaErdoganOzkoca Posts: 19 Bronze 3
    Hi,

    When you run Get-SqlClone, cmdlet returns you a CloneResource object which includes LocationId. But the problem is, it is not possible to get the SqlServerInstance by using this LocationId. A basic solution is, you can query all Sql Server Instances by using Get-SqlCloneSqlServerInstance and you can try to find the LocationId in the result of Get-SqlCloneSqlServerInstance. You can find an example query below.

    Connect-SqlClone -ServerUrl 'http://your_sql_clone_server_url'
    $clone = Get-SqlClone -Name 'your_clone_name'
    $cloneLocationId = $clone.LocationId
    $sqlServerInstances = Get-SqlCloneSqlServerInstance
    foreach($instance IN $sqlServerInstances)
    {
       if($instance.Id -eq $cloneLocationId)
       {
          Write-Output $instance
       }
    }

Answers

  • RyanHRyanH Posts: 2 Bronze 1
    That does the job nicely, thanks.
    I'd seen the location id but hadn't put it together that that was the id of the server.

    It would be handy as a future improvement if both Get-SqlClone and Get-SqlCloneSqlServerInstance both returned the LocationId property

Sign In or Register to comment.