Friday, April 1, 2011

CLUSTER NAME, VIRTUAL RESOURCE NAME, PHYSICAL SERVER NAME(S)

IF (SELECT CONVERT(bit, SERVERPROPERTY('IsClustered'))) = 1
      BEGIN
            DECLARE @ClusterName VarChar(1000)       
            EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='Cluster', @value_name='ClusterName', @value=@ClusterName OUTPUT
           
            SELECT
            Upper(NodeName) as PhysicalServerName
            ,Upper(CONVERT(varchar(100), SERVERPROPERTY('MachineName'))) as [VirtualPhysicalName]
            ,Upper(@ClusterName) as ClusterName
            FROM sys.dm_os_cluster_nodes 
      END
      ELSE
      BEGIN
            SELECT
            Upper(CONVERT(varchar(100), SERVERPROPERTY('MachineName'))) as [PhysicalServerName]
            ,Upper(CONVERT(varchar(100), SERVERPROPERTY('MachineName'))) as [VirtualPhysicalName]
            ,NULL as ClusterName
      END

No comments:

Post a Comment