Script to list the cluster servers (PowerShell)

Introduction

This script will demo how to list the servers in one or more Windows clusters.

Scenarios

Sometimes, IT pro need to list all servers in the specified cluster(s).This script is to accomplish it.

Script

This script contains one  advanced function, Out-OSCClusServers, You can use this script in the following ways:
Method:
1.Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
2.Run Import-Module cmdlet to import this module file.
        Import-Module filepath\scriptname.psm1
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
$Clusters = Import-Csv-Path $ClusFilePath#Loop the clusters in the fileForeach($Clusterin$Clusters) 
{ 
    $ClusterName = $Cluster.ClusterName 
    $Result = GetClusterServers $ClusterNameIf($Result-ne $null) 
    {     
        #Export the server the cluster$Result|Out-File -FilePath $OutFilePath-Append 
        $flag++ 
    } 
}

Examples   

Example 1: Get help about  Out-OSCClusServers      
Command
:   Get-Help Out-OSCClusServers -Full
Screenshot:
 
Example 2: Get all servers in the specified cluster and
store them in the specified file.
Command:   Out-OSCClusServers -ClusterName "mac-clus" -OutFilePath c:\OneScript\result.csv
Screenshot:

Example 3: Get all servers in the specified clusters in
CSV file and store them in specified file.
Command:   Out-OSCClusServers -ClusFilePath
'c:\OneScript\ClusNames.csv' -OutFilePath c:\OneScript\result.csv
Screenshot:

Note: The CSV file format should be like this.             
ClusterName            
mac-clus
abc

Prerequisite      

Windows PowerShell 2.0

Additional Resources

Related forum threads:
Script to report on a MSCS Cluster server