The content of the pscustomobject is sort of this:
MyCatalog-N01-STANDARD
MyCatalog-N65-PREMIUM
…and so on.
I would like to check against this pscustomobject now whether it contains a certain pattern. I tried -match and -contains but both fail. I read in the about_Comparison_Operators and found that -match does only support strings…
My aim is to get a true or false return if I query the pscustomupject like this:
$catalogselection -contains “N01”, “PREMIUM”
My expectation = false
$catalogselection -contains “N65”, “PREMIUM”
My expectation = true
I’m really out of ideas here on howto get this solved.
Not sure I understand your requirements fully, but the -match operator is interesting and I have been wanting to learn regex…
Here are some interesting results… Your example PS $catalogselection.brokercatalog -match “N01”, “STANDARD” syntax isn’t something I could find, but I think I duplicated the sentiment:
May not fit your use case, but this definitely gives me a reason to learn regex. I gave my objects two properties since it seems like a one property object would be better served by an array of strings, so I wanted it to fit what I see more.
So, to be more specific, I think your command would be PS $catalogselection.brokercatalog -match “N01.*STANDARD” if you wanted every item that contains both substrings and
PS $catalogselection.brokercatalog -match “N01|STANDARD” if you wanted either of them.
I’m definitely an amateur with the regex, so it’s important to note the limited scope of my example, but this works with a string array too. Sequence is important in this example, but I know there are ways to ignore the sequence… I’ll look for one of those, but see this example:
[E:\g.working\regex]
#$arry -match “e”
Blue
Red
Yellow
Green
Purple
Orange
White
[E:\g.working\regex]
#$arry -match “l.*e”
Blue
Purple
[E:\g.working\regex]
#$arry -match “e.*l”
Yellow
$arry=@("Blue","Red","Yellow","Green","Purple","Orange","White","Black")
$arry
$arry -match "e" # Match strings containing "e"
$arry -match "l.*e" # Match strings with "l" followed by "e"
$arry -match "e.*l" # Match strings with "e" followed by "l"