Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Determining if a server is clustered or stand-alone Expand / Collapse
Author
Message
Posted Tuesday, September 27, 2011 2:14 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 19, 2014 10:36 AM
Points: 317, Visits: 878
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
Post #1182082
Posted Tuesday, September 27, 2011 2:26 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:09 AM
Points: 12,965, Visits: 32,541
colleen i know that via TSQL you can get the serverproperty:

would that help?
SELECT 'IsClustered', SERVERPROPERTY('IsClustered')



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1182089
Posted Tuesday, September 27, 2011 2:54 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:31 AM
Points: 6,748, Visits: 8,546
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


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

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


- 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
Post #1182104
Posted Thursday, September 29, 2011 8:34 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 19, 2014 10:36 AM
Points: 317, Visits: 878
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
Post #1183205
Posted Friday, September 30, 2011 11:21 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 11:44 AM
Points: 60, Visits: 900
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" }
Post #1183856
Posted Tuesday, October 4, 2011 9:22 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, September 19, 2014 2:56 PM
Points: 58, Visits: 260
$s = New-Object Microsoft.SqlServer.Management.Smo.Server("$instancename");
$s.IsClustered; # returns $true/$false accordingly.
Post #1185335
Posted Wednesday, March 6, 2013 11:19 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 19, 2014 4:20 PM
Points: 2, Visits: 241
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
Post #1427542
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse