Another option to help address the problem with 11.2 and 1.13 is to type cast
the version as a "[System.Version]" type. You can use this to get the version
number:
$FilePath = 'C:\Program Files\AppSense\Environment
Manager\Agent\EMCoreService.exe'
$File = Get-Command $FilePath
$FileVersionInfo = @(
$File.FileVersionInfo.FileMajorPart,
$File.FileVersionInfo.FileMinorPart,
$File.FileVersionInfo.FileBuildPart,
$File.FileVersionInfo.FilePrivatePart
)
$FileVersion = [Version]($FileVersionInfo -join '.')
Now to compare this against another file, you can use:
If ($FileVersion -lt [Version]'8.4.495.0') { #do something }
-Aakash Shah
From: [email protected] [mailto:[email protected]] On
Behalf Of James Rankin
Sent: Thursday, April 3, 2014 1:20 PM
To: [email protected]
Subject: Re: [NTSysADM] PowerShell tidy-up
Very good point. Luckily what I am dealing with here should all start as 8.4
and have xxx.x as the last numbers, but I will pay a lot of attention to that
in future, cheers!
On 3 April 2014 21:16, Ben Scott
<[email protected]<mailto:[email protected]>> wrote:
On Thu, Apr 3, 2014 at 2:59 PM, James Rankin
<[email protected]<mailto:[email protected]>> wrote:
> I did this quick bit of PS to check a file version number and then launch a
> patching process if it isn't at a certain level. It works OK but I am sure
> there is a much cleaner and more elegant way to do this. Any pointers?
More of an observation than a suggestion:
Testing version numbers is one of those things that you'd think
would be easy but ends up being ridiculously complicated. Removing
separators and just treating it as one big number seems like a good
idea unless you want to compare version 11.2 with version 1.13. Plus
some people throw in letters. Testing release dates might seem like a
good alternative, but if the publisher is maintaining multiple release
branches, patch release 1.1.42 might be released after major release
2.0.0. Blech.
If the possible version numbers are more controlled, your method is
usually fine.
-- Ben
--
James Rankin
---------------------
RCL - Senior Technical Consultant (ACA, CCA, MCTS) | The Virtualization
Practice Analyst - Desktop Virtualization
http://appsensebigot.blogspot.co.uk