[Edit after both answers said lack of clarity] My Goal: Perform different operations depending if what is passed to a function is an "object" type thing (e.g. an array, a hashtable) or just a simple "string" type thing. If it's just a string, I'll simply include it in the body of the email. If it's an array or hashtable, I need to do a bunch of processing on it to convert it into an HTML table.
[Original Question Text]
I'm passing a variable $body
to a function Email-Report
that can either be a simple string or an object (e.g. a hashtable or array).
I want to check if $body
is an object and do different things depending.
My problem is $body
could be almost anything, not just a string or a hashtable. So I can't just check if $body.GetType().Name -eq String
I've tried $body.GetType().Name
which returns
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
However if the variable is an array BaseType
becomes System.Array
so I can't filter on that property, also as mentioned above the $body
variable may not always be a hashtable or an array.
If it's a hash table, $var.GetType()
returns a BaseType of System.Object
, however I can't seem to refer to the BaseType property.
($hash.GetType()).BaseType
returns another object itself, which itself has a BaseType property which is blank.
I've also tried $body.IsObject
and $body.IsObject()
but those methods don't seem to exist. I've also tried $body -eq [System.Object]
which I expected to be $true
, but it returns $false
.
Not sure where to go from here - I think I'm missing something obvious or having a logic error.