Determining if a server is clustered or stand-alone

  • I'm in the process of writing a powershell script to inventory my SQL Server environment. In collecting the server information, I'd like to grab the physical hostnames that make up any clustered environments. I know I can use

    $nodes=get-clusternode -Cluster SERVERNAME |select name

    to get the physical servers in the cluster, but if I run that on a non-clustered server, I get an error, obviously. So, can someone recommend a good way to determine whether the SERVERNAME I've connected to is a cluster resource group or a physical stand-alone server?



    Colleen M. Morrow
    Cleveland DBA

  • colleen i know that via TSQL you can get the serverproperty:

    would that help?

    SELECT 'IsClustered', SERVERPROPERTY('IsClustered')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • this may be to primitive but you could just use a try catch block to try get-cluster or get-clusternode and have the catch block handle stand-alone servers.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Thanks for the ideas. I think I've got a solution that works:

    $s=Get-WMIObject -query "select * from Win32_ComputerSystem" -ComputerName $server | select name

    if ($s -ne $server) {

    Write-Output "$server is clustered"

    } else {

    Write-Output "$server is not clustered"

    }

    Colleen



    Colleen M. Morrow
    Cleveland DBA

  • Another option is to look for the cluster service

    $s = Get-WmiObject -Class Win32_SystemServices -ComputerName $server

    if ($s | select PartComponent | where {$_ -like "*ClusSvc*"}) { Write-Output "$server is Clustered" }

    else { Write-Output "$server is Not clustered" }

  • $s = New-Object Microsoft.SqlServer.Management.Smo.Server("$instancename");

    $s.IsClustered; # returns $true/$false accordingly.

  • Thanks all - this helped me keep my application event log clean.

    bool isClustered = false;

    ManagementObjectSearcher searcher = new ManagementObjectSearcher(

    new ManagementScope(string.Format("\\\\{0}\\root\\cimv2", machineName))

    , new ObjectQuery("SELECT PartComponent FROM Win32_SystemServices"));

    foreach (ManagementObject iQueryObj in searcher.Get())

    {

    string name = iQueryObj["PartComponent"].ToString();

    if (name.Contains("ClusSvc"))

    {

    isClustered = true;

    }

    }

    Jeff Gogel

  • I had to change it to this to get it to work:

    if ($s.Name -ne $server) {

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply