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

Time:03-05

I build the following script for debugging:

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

# Get VerionInfo
$Version = $File.VersionInfo

# Print VersionInfo
Write-Output "$Version"

which results in this output:

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)

Putting the script in this inline function:

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

results in a completely different output:

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

How can I get the first output, using an inline function?

CodePudding user response:

The following code fixes my issue:

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

Thanks to Mathias R. Jessen and Jeroen Mostert for explaining the reason and solving my issue.

  • Related