September 27, 2011 at 2:14 pm
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?
September 27, 2011 at 2:26 pm
colleen i know that via TSQL you can get the serverproperty:
would that help?
SELECT 'IsClustered', SERVERPROPERTY('IsClustered')
Lowell
September 27, 2011 at 2:54 pm
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
September 29, 2011 at 8:34 am
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
September 30, 2011 at 11:21 am
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" }
October 4, 2011 at 9:22 am
$s = New-Object Microsoft.SqlServer.Management.Smo.Server("$instancename");
$s.IsClustered; # returns $true/$false accordingly.
March 6, 2013 at 11:19 am
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
September 25, 2015 at 3:30 pm
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