I'm trying to run commands on a remote host and use the results. In this case, "Get-Item". (In my "real" code, I call Get-Item several times and return a custom object with several items - but that doesn't matter for this example).
I've run into this problem where if I return the results from Get-Item (A System.IO.FileSystemInfo.FileInfo), the "VersionInfo" gets turned into a string, so I cannot reference $result.VersionInfo.FileVersion.
Example below -- "$b" is the whole get-item result, while "$a" is (Get-Item).VersionInfo.
"$a.FileVersion" is a string as expected. But, why is "$b.VersionInfo" a string instead of an object with some properties?
PS C:\Tests> $b=invoke-command -Session $Session -ScriptBlock { get-item "C:\SomeThing.dll"}
PS C:\Tess> $b.versioninfo.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS C:\Tests> $a=invoke-command -Session $Session -ScriptBlock { (get-item "C:\SomeThing.dll").VersionINfo}
PS C:\Tests> $a
ProductVersion FileVersion FileName
-------------- ----------- --------
2.9.0 2.9.0 C:\SomeThing.dll
PS C:\Tests> $a.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True PSObject System.Object
PS C:\Tests> $a | get-member
TypeName: Deserialized.System.Diagnostics.FileVersionInfo
Name MemberType Definition
---- ---------- ----------
FileVersion Property System.String {get;set;}