Get cluster information remotely using PowerShell

Today I want to show you how to get cluster information remotely using simple PowerShell function. To pull all needed information about our cluster we will use some dedicated cmdlets which can be found here.

On the beginning script will check if module for failover clustering is installed – Import-Module FailoverClusters.

Then we need to ensure that server provided as a parameter exist and cluster service is running. To do this I used simple method which is checking servers IP address. If it can’t determine what is the server address it will throw warning message – Write-Warning “Server does not exist”. Additionally we can use Get-Service command to just simple check if cluster is running. If not, script will ends.

Please remember to add your cluster server names in function parameter:


    param
    (
        [Parameter(Position=1, Mandatory = $True, HelpMessage="Select cluster server", ValueFromPipeline = $true)]
        [ValidateSet("Server01","Server02","Server03","Server04")]
        $Server
    )

Final script:


function Get-ClusterData {
         
    [CmdletBinding()]
    param
    (
        [Parameter(Position=1, Mandatory = $True, HelpMessage="Select cluster server", ValueFromPipeline = $true)]
        [ValidateSet("Server01","Server02","Server03","Server04")]
        $Server
    )
 
        # Checking module
        Try
        {
            Import-Module FailoverClusters -ErrorAction Stop
        }
        Catch
        {
            $_.Exception.Message
            Write-Output "Failover cluster module not installed!"
            Break
        }
 
        Write-Host "Processing $server" -ForegroundColor Green
      
            # Checking if server exist           
            $hostname = [System.Net.Dns]::GetHostAddresses($Server)    
      
                # Proceed if IP address found
                If($hostname.ipaddresstostring)
                {
 
                    # Check if cluster service is running
                    Try 
                    { 
                        If (!(Get-Service -ComputerName $Server |  Where-Object  {$_.Displayname -match "Cluster*"}).Status -eq "Running") {throw}
                    }
                    Catch 
                    {
                        Write-Warning 'Cluster service is not "Running"'
                        Read-Host -Prompt "Press Enter to exit..."
                        Break
                    } 
 
		            Try
		            {
			            # If checks passed then get cluster information
            		    Invoke-Command -ComputerName $Server -ErrorAction Stop -ScriptBlock{                   
                    	
                            Write-Output "Checking cluster recources:"
		    		        Get-ClusterResource  | select ownernode,iscoreresource,name,resourcetype,state,characteristics | ft -auto
 
                    		Write-Output "Checking cluster owner nodes:"
                    		Get-ClusterGroup  | select cluster,Iscoregroup,ownernode,state,name | sort state | ft -AutoSize
 
                    		Write-Output "Checking cluster nodes:"
                            Get-ClusterNode | select cluster,name,state,nodeweight | ft -auto
 
                    		Write-Output "Checking file share witness availablity:"
                    	 	Get-ClusterResource | Where-Object  {$_.Name -eq "File Share Witness"}  | select name,state | ft -AutoSize
			            }
		            }
		            Catch
		            {
 			            $_.Exception.Message
            		    Break
		            }
    
                }
                Else
                {
                    Write-Warning "Server does not exist"
                }
 }

2 thoughts on “Get cluster information remotely using PowerShell

    1. Its difficult to tell because you didn’t provide details. Did you put your servers into:
      [ValidateSet(“Server01″,”Server02″,”Server03″,”Server04”)]

      What prompt message do you get? Do you have admin rights to get cluster information? What about connectivity from place where you running this script?

      Please also check if you have failover cluster module installed.
      Get-Module FailoverClusters

      Kind regards

Leave a Reply

Your email address will not be published. Required fields are marked *