Sunday, 14 August 2011

Show-MajorPart.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script shows the Major part of the version number 
  4.     of file version object. 
  5. .DESCRIPTION 
  6.     This script is a re-implementation of an MSDN Sample script 
  7.     that uses System.Diagnostics.FileVersionInfo to get 
  8.     the major part of the version number of the file. 
  9. .NOTES 
  10.     File Name  : Show-MajorPart.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2011/08/show-majorpartps1.html 
  16.     MSDN sample posted to: 
  17.          http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.filemajorpart.aspx   
  18. .EXAMPLE 
  19.     Psh> .\Show-MajorPart.ps1 
  20.     File Major Part for C:\Windows\system32\Notepad.exe is: 6             
  21. #> 
  22. # Set filename 
  23. $File = [System.Environment]::SystemDirectory + "\Notepad.exe" 
  24.  
  25. #Get Version information for this file 
  26. $myFileVersionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File
  27.  
  28. # Print the Build details name 
  29. "File Major Part for {0} is: {1}"  -f $file,$myFileVersionInfo.FileMajorPart