I am not sure what I am doing wrong here:
$ZertoGenericAlert = "VRA0030"
$ZvmToVraConnection = "ZVM0002"
$ZvmToZvmConnection = "ZVM0003", "ZVM0004"
$thoseerrors = "ZVM0002", "VPG0006", "VPG0004" , "ZVM0003", "ZVM0004"
if ($thoseerrors -contains $ZvmToZvmConnection) {Echo "bingo"} Else {Echo "fail"}
It keeps coming as "fail" when I run that that entire piece of code
It gives me "Bingo" when ONLY 1 item is found in the $zvmtozvmconnection
Ie I remove "ZVM0004" and only "ZVM003" remains i get "Bingo"
I also tested -match and that did not work either
Please help
-contains doesn't work that way. It checks if a single item is contained in an array. -in is the same, with the other order ($array -contains $item or $item -in $array).
You should use the Compare-Object cmdlet for this:
if ((Compare-Object -ReferenceObject $thoseerrors -DifferenceObject $ZvmToZvmConnection -ExcludeDifferent -IncludeEqual)) {
'bingo'
} else {
'fail'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With