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

后端 未结 2 1118
误落风尘
误落风尘 2021-01-19 02:47

Take the simple HashTable:

$data = @{
    First = \'Justin\';
    Last = \'Dearing\';
    StartDate = Get-Date \'2002-03-23\';
}

The key St

相关标签:
2条回答
  • 2021-01-19 03:41

    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.

    0 讨论(0)
  • 2021-01-19 03:45

    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
    
    0 讨论(0)
提交回复
热议问题