I want to loop through a bunch of objects and check each object's properties to see if it is a single value (string or int) or if it is an object/array (doesn't matter if it contains anything just see if it is an object or array).
I was going to just do a check to see if each property is a string or and integer, but is there a more efficient way?
$object -is [Array]
The -is
operator checks whether an object is a certain type.
Edit: maybe what you want is to see if it's a Value Type?
$object.GetType().IsValueType
Update: TamusJRoyce mentioned in a comment that they didn't see an .IsValueType
property, and suggested this, which is more idiomatic and might work in more situations:
$value -is [System.ValueType]
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