I have the following snippet of PowerShell:
$property = @{
Getter = { 80 };
}
$value = $property.Getter.Invoke()
$value.GetType() # Shows Name = Collection'1 instead of int
I would expect $value.GetType() to return Int32 but instead it returns a collection.
I can't just take element [0] because sometimes the Getter function will return an array.
How can I fix this?
(,$value)[0]will give you the first element of the returned collection (and it always returns a collection, because that's the signature ofScriptBlock.Invoke()) without eagerly unrolling it if it's enumerable.$property.Getter.InvokeReturnAsIs().GetType()