Why does Get-Date seem to return DateTime objects, but the BinarySerializer indicate it returns a PSObject?

不问归期 提交于 2019-12-01 18:22:14

Every object in powershell is actually wrapped mostly transparently in a psobject. I say mostly transparently because there are more than a few bugs in powershell that omit to remove the wrapper before leaking the object to another API. This causes all sorts of issues, much like the one you see now. Search connect.microsoft.com/powershell for psobject wrapper. I believe this is no longer an issue in v3 with the new DLR based engine.

Base on the msdn:

PSOobject Class : Encapsulates a base object of type Object or type PSCustomObject to allow for a consistent view of any object within the Windows PowerShell environment.

 ( get-Date '2002-03-23' ) -IS [psobject]
True

( get-Date '2002-03-23' ) -IS [datetime]
True

[datetime]( get-Date '2002-03-23' ) -IS [datetime]
True

[datetime]( get-Date '2002-03-23' ) -IS [psobject]
False
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!