1

I want to extract verssion number from MFC *.rc file. It looks like:

  VALUE "FileVersion", "1.22.333.4444\0"

actually I need two values - version 1.22.333.4444 and major version 1.22

I wrote the code below and it gives me the version, but it looks ugly

  $version = Get-Content -Path $rcPath | Select-String -Pattern 'FileVersion' -CaseSensitive –SimpleMatch -List | %{$_ -replace '[\\0]', ''} | %{$_ -replace '[^\d.]', ''}

So my questions are:

  • Is there any simple way to obtain the version?
  • How I can get the major version?

1 Answer 1

7

There's a [Version] type you can use for that:

$text = 'VALUE "FileVersion", "1.22.333.4444\0"'
$version = [version]($text -replace '^.+?([0-9.]+)\\.+','$1')
$version


Major  Minor  Build  Revision
-----  -----  -----  --------
1      22     333    4444    

Then:

$version.ToString()

1.22.333.4444

'{0}.{1}' -f $version.major,$version.minor

1.22
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.