I was writing a function today where I need the outcome to be true if A or B equal C, where see is the results of a Get-ItemProperty
Originally I had:
If $a -eq Get-ItemProperty…
Of course in order to avoid running the Get-ItemProperty cmdlet twice (due to needing to comapre it against $b as well) I have assigned the results to variable $C for use in the if statement.
Normally I would write this If A equals C or If B Equals C but was wondering, is there is a way to structure this as If A or B equal C?
Not really a big deal I was just curious if it were possible.
Yep, definitely possible. I’d probably not want to do the first one there if the array is fairly large, it’d make PS do a lot of extra work (building a whole new array, etc.) that isn’t needed in this instance.
Good call on -match, but important to remember it only works if your values are strings, or can be accurately represented when converted to strings.
Yeah, foreach just accesses each item in the array in turn, so it won’t use much, if any, extra memory. However, creating a new array does create some overhead in terms of extra memory (the amount will of course still vary based on the sizes of the arrays involved and what they contain).