Take the simple HashTable:
$data = @{
First = 'Justin';
Last = 'Dearing';
StartDate = Get-Date '2002-03-23';
}
The key StartDate seems to contain a DateTime.
C:\Users\zippy\Documents> $data.StartDate.GetType().FullName
System.DateTime
However, if I attempt to perform binary serialization on it, I get an exception complaining that PSObject is not serializable.
$ms = New-Object System.IO.MemoryStream
$bf = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
$bf.Serialize($ms, $data)
$ms.Close()
Throws:
DocumentsException calling "Serialize" with "2" argument(s): "Type 'System.Management.Automation.PSObject' in Assembly 'System.Management.Automation, Versio
n=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."
At C:\Users\jdearing\AppData\Local\Temp\b8967f99-0a24-41f7-9c97-dad2bc288bd9.ps1:12 char:14
+ $bf.Serialize <<<< ($ms, $data)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
This message goes away and everything works if I use an explicit cast to [DateTime] like so:
$data = @{
First = 'Justin';
Last = 'Dearing';
StartDate = [DateTime] (Get-Date '2002-03-23');
}
So is Get-Date not really returning a DateTime, or is some other powershell oddity at work here.