Powershell for windows clusternode

HI all,

I have no background of scripting and very little idea since I have stated to learn now,
I want to write a code for Cluster node, if the state of server is up then print the output
and if state of any node is down, the code should print the output

I was able to do for file share witness since output was of single line,
but for cluster node I am unable to figure out the code since there are 3 line in output, i am not sure how the get-clusternode output will be stored in variable
can someone help on this? would really appreciate it.

File share witness

$s = Get-ClusterResource -Cluster servername -name “File Share Witness*”
$state = $s.state

if ( $state -match ‘up’)


“File Share Witness status =” + " " + “$state”

if ( $state -match ‘down’)


“File Share Witness status =” + " " + “$state”


Name State OwnerGroup ResourceType

File Share Witness Online Cluster Group File Share Witness

this is the requirement need to check if name of server in this case A,B,C is up then print the output or else if state is down then print the output

command: get-clusternode


Name ID state
A 1 up
B 2 up
C 3 up

code for cluster node

$ser = Get-Clusternode
$state = $ser.state

foreach state$
if ( $state -match ‘Online’)


“File Share Witness status =” + " " + “$state”

if ( $state -match ‘Failed’)


“File Share Witness status =” + " " + “$state”


Welcome to the forum. :wave:t3:

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you potentially wasting their time.