Retrieve product version at runtime

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
sschimkat
Posts: 1
Last visit: Wed Dec 20, 2023 1:44 am

Retrieve product version at runtime

Post by sschimkat »

Hi all

I need to be able to retrieve the version of the compiled .exe running my script, but I'm having trouble with figureing out how to do it. With regular .Net I would use Assembly.GetExecutingAssembly(), but I'm not quite sure on how to something similar with PowerShell.

Any hints on this one please? :-)
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Retrieve product version at runtime

Post by Alexander Riedel »

  1. if ($null -ne $hostinvocation)
  2. {
  3.     $HostFile = $hostinvocation.MyCommand.path
  4.     (Get-Command $HostFile).FileVersionInfo.FileVersion
  5. }
The version number parts of the File­Version­Info are
Product Field	        File Field	         Meaning	         Example
----------------------------------------------------------------------------------------
ProductVersion	        FileVersion	String version	3.1.0.2 (alpha)
ProductMajorPart	FileMajorPart	First number	3
ProductMinorPart	FileMinorPart	Second number	1
ProductBuildPart	FileBuildPart	Third number	0
ProductPrivatePart	FilePrivatePart	Fourth number	2
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.