Careful with VersionInfo…

Last week I volunteered to write PowerShell script that meant to test image (Win7) against a set of requirements. As a base I used JScript that was used for Windows XP machines in a past. When writing this code I wanted to do as much as I can using dot.net rather than com objects (that was common for JScript/ VBScript). But I failed with file version for winzip. Why? Let’s see…

PowerShell, using GeSHi 1.0.8.8
  1. PS C:> ls ‘C:Program FilesWinZipWINZIP32.EXE’ | select -ExpandProperty VersionInfo
  2.  
  3. ProductVersion   FileVersion      FileName                                                                       
  4. ————–   ———–      ——–                                                                       
  5. 9.0 SR1 (6224)  18.0 (32bit)    C:Program FilesWinZipWINZIP32.EXE                                           

Yak. Where is my version number? What the heck that (32-bit) is doing there? So… I eventually used $fso for that..:

PowerShell, using GeSHi 1.0.8.8
  1. PS C:> $fso = New-Object -ComObject Scripting.FileSystemObject
  2. $fso.GetFileVersion(‘C:Program FilesWinZipWINZIP32.EXE’)
  3. 18.0.6224.0

Much better. But I was digging deeper – where those properties are hidden in .NET? And I found it… :

PowerShell, using GeSHi 1.0.8.8
  1. PS C:> ls ‘C:Program FilesWinZipWINZIP32.EXE’ | select -ExpandProperty VersionInfo | select File*Part
  2.  
  3.            FileBuildPart           FileMajorPart           FileMinorPart         FilePrivatePart
  4.            ————-           ————-           ————-         —————
  5.                     6224                      18                       0                       0

All is there, only divided. But to be honest $fso version was easier for me to consume, so I left it like that. Job done, so I’m fine with that. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s