为什么 Powershell 在 Write-Output 上内联 VersionInfo 会提供不同的输出?

Why does Powershell inline VersionInfo on Write-Output delivers a different output?

我构建了以下调试脚本:

# Store file in var
$File = (Get-ChildItem -Path [ANY_EXE].exe)

# Get VerionInfo
$Version = $File.VersionInfo

# Print VersionInfo
Write-Output "$Version"

导致此输出:

File:             [ANY_EXE].exe
InternalName:     [ANY_EXE]
OriginalFilename: [ANY_EXE]
FileVersion:      8.20.1.14183
FileDescription:  [DESCRIPTION_FOR_EXE]
Product:          [PRODUCT_FOR_EXE]
ProductVersion:   8.20
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Englisch (Vereinigte Staaten)

将脚本放入此内联函数中:

Write-Output (Get-ChildItem [ANY_EXE].exe).VersionInfo

导致完全不同的输出:

ProductVersion   FileVersion      FileName                                                                                  
--------------   -----------      --------                                                                                  
8.20             8.20.1.14183     [ANY_EXE].exe    

如何使用内联函数获得第一个输出?

以下代码解决了我的问题:

(Get-ChildItem [ANY_EXE]exe).VersionInfo -as [string]

感谢 Mathias R. JessenJeroen Mostert 解释原因并解决了我的问题。