Skip to content

Commit e0e7bad

Browse files
committed
Test-DbaDiskAlignment - Reach a failover cluster instance through its virtual name
The SQL check built instance names from the Win32_Service list of the node, but a failover cluster instance only listens on its virtual server name. Every connection attempt burned the full timeout and no disk ever qualified as a SQL disk, so the command took six minutes to return nothing. The virtual name is now read from the ClusterName value of the instance hive over the existing CIM session; stand-alone instances keep using the node name. (do Test-DbaDiskAlignment)
1 parent 0473789 commit e0e7bad

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

public/Test-DbaDiskAlignment.ps1

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,45 @@ function Test-DbaDiskAlignment {
182182

183183
$instanceName = $instance.Replace("MSSQLSERVER", "Default")
184184
Write-Message -Level Verbose -Message "Found instance $instanceName" -FunctionName $FunctionName
185+
186+
# A failover cluster instance is reached through its virtual server name, not through
187+
# the name of the node it currently runs on. The virtual name is in the ClusterName
188+
# value of the Cluster key of the instance hive, which only exists for clustered instances.
189+
$connectionName = $ComputerName
190+
$splatRegistryHive = @{
191+
CimSession = $cimSession
192+
Namespace = "root/default"
193+
ClassName = "StdRegProv"
194+
MethodName = "GetStringValue"
195+
Arguments = @{
196+
hDefKey = [uint32]2147483650 # HKEY_LOCAL_MACHINE
197+
sSubKeyName = "SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"
198+
sValueName = $instance
199+
}
200+
}
201+
$instanceHive = (Invoke-CimMethod @splatRegistryHive).sValue
202+
if ($instanceHive) {
203+
$splatClusterName = @{
204+
CimSession = $cimSession
205+
Namespace = "root/default"
206+
ClassName = "StdRegProv"
207+
MethodName = "GetStringValue"
208+
Arguments = @{
209+
hDefKey = [uint32]2147483650 # HKEY_LOCAL_MACHINE
210+
sSubKeyName = "SOFTWARE\Microsoft\Microsoft SQL Server\$instanceHive\Cluster"
211+
sValueName = "ClusterName"
212+
}
213+
}
214+
$clusterName = (Invoke-CimMethod @splatClusterName).sValue
215+
if ($clusterName) {
216+
Write-Message -Level Verbose -Message "Instance $instanceName is clustered, using virtual server name $clusterName" -FunctionName $FunctionName
217+
$connectionName = $clusterName
218+
}
219+
}
185220
if ($instance -eq 'MSSQLSERVER') {
186-
$SqlInstances += $ComputerName
221+
$SqlInstances += $connectionName
187222
} else {
188-
$SqlInstances += "$ComputerName\$instance"
223+
$SqlInstances += "$connectionName\$instance"
189224
}
190225
}
191226
$sqlcount = $SqlInstances.Count

0 commit comments

Comments
 (0)