I need a powershell script which gets information from another powershell script.
It seems to me the it is an array what I get in my script, so I tried to compare one item or the whole array against a string.
I will execute then this command on our Exchange cluster:
Get-ClusterResource |fl State|.\CheckDAG1.ps1
The first script is an inbuild Exchange script to get the state of a fileshare witness, the second script is mine and looks like this:
Param (
[parameter(ValueFromPipeline=$True)]
[string[]]$Status
)
echo $Input.count
echo $Input
if ($input[2] -contains "Online") {
echo "1"}
else {
echo "0"}
The output is this:
5 State : Online 0
So I can see that the array has 5 items, item 2 is the written line, but the result is 0.
What can I do so that the result is 1 as I expect?

Format-Listin the middle of the pipe; just write your script to use whateverGet-ClusterResourcereturns, and extracts theStateproperty for examination and processing.-containsis the wrong operator to use here. You're comparing two single values;-containsis to see if a collection object (e.g., an array) has a particular value as one of its entries. Use-eqfor a (case-insensitive) exact match,-likefor a pattern match with simple wildcards, or-matchfor a pattern match using a regular expression.