In a PowerShell script, I need to determine whether a .NET method call is actually returning the correct type of object, or at least a compatible type. How can I do this?
Asked
Active
Viewed 4,724 times
2 Answers
32
Something like this:
$a -is [string]
Or you can use GetType() and see whether the type is what you want.

manojlds
- 290,304
- 63
- 469
- 417
-
@JaySullivan "powershell is operator" are great terms for it. – jpmc26 Mar 13 '15 at 05:26
-
2@jpmc26: Well yes, it is *now*, because when I search "powershell is operator" on Google, *this* Stackoverflow question is the first result. None of the other search results are relevant. – Jay Sullivan Mar 13 '15 at 15:41
6
$yourObject.pstypenames will return the complete inheritance chain.

David Brabant
- 41,623
- 16
- 83
- 111