How to get information of cluster nodes with Powershell and print node status

171 Views Asked by At

I want to perform validation and print output of cluster node in powershell

cmd

Get-ClusterNode

output:

Name ID State
node1 1 Up
node2 2 Up
node3 3 Up
node4 4 Up

for instance in this output, I need to check if the node status is up then print node name and state and if any of node is down then it should print that one of the node is down with the name of down node.

I have no background of scripting but I wrote this script can anyone please check if this would give the proper output, I used foreach since state of all node is need to be checked and then I tried to print it.

thanks!!

$node = Get-Clusternode
$state = $node.state

foreach state$
{
    if ( $state -match 'Up')
    {
        'File Share Witness status =' + ' ' + "$state"
        exit0
    }

    if ( $state -match 'Failed')
    {
        'File Share Witness status =' + ' ' + "$state"
        exit0
    }
}
0

There are 0 best solutions below