Created
February 18, 2022 14:53
-
-
Save wsmelton/4fd1314138a10f02d709fa2aa5cf0cee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cmdletbinding()] | |
param( | |
[string] | |
$VMName | |
) | |
$scriptBlock = { | |
$clusterNetworkNames = Get-ClusterResource | Where-Object ResourceType -eq 'Network Name' | |
foreach ($n in $clusterNetworkNames) { | |
if ($n.Name -match 'SQL Network Name') { | |
$hostValue = $n.Name.TrimStart('SQL Network Name (').TrimEnd(')') | |
$fqdn = [System.Net.Dns]::GetHostByName($hostValue).Hostname | |
} else { | |
$fqdn = [System.Net.Dns]::GetHostByName($n.Cluster).Hostname | |
} | |
[pscustomobject]@{ | |
ClusterName = $n.Cluster | |
Name = $n.Name | |
OwnerNode = $n.OwnerNode | |
FQDN = $fqdn | |
} | |
} | |
} | |
try { | |
Invoke-Command -ComputerName $VmName -ScriptBlock $scriptBlock -ErrorAction Stop | Format-Table ClusterName, Name, OwnerNode, FQDN | |
} catch { | |
throw "Issue connecting to $VMName - $($_)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment