0

I want to create a powershell script to pull specific data from a specific property from a specif file. So in a nutshell. I want to get the FileVersion data out of the property of versioninfo from a .exe.

I'm using the following command to get file and view the property value from above.

dir c:\windows\system32\dfc.exe | fl versioninfo

the output is has follows

VersionInfo : File:             C:\windows\system32\dfc.exe
          InternalName:     dfcmnd.exe
          OriginalFilename: DFC.exe
          FileVersion:      7,30,220,3852
          FileDescription:  Command line utility for Deep Freeze 7.00
          Product:          Deep Freeze 7.00
          ProductVersion:   7.30.220.3852
          Debug:            False
          Patched:          False
          PreRelease:       False
          PrivateBuild:     False
          SpecialBuild:     False
          Language:         English (United States)

but all that I want is

Fileversion: 7.30.220.3852

I can not think of a way to get just that data out and discard the rest.

Thanks.

2 Answers2

2

If you just want the value then just access the attributes:

PS D:\> (get-item c:\windows\system32\write.exe).VersionInfo.FileVersion
6.1.7600.16385 (win7_rtm.090713-1255)

N.B. If you use a wildcard to match multiple files this won't work on Powershell v2, but it will work on more recent Powershell versions.

If you want an object with just a FileVersion attribute then use select:

PS D:\> (get-item c:\windows\system32\write.exe).VersionInfo | select FileVersion

FileVersion                                                                                                                                                                       
-----------                                                                                                                                                                       
6.1.7600.16385 (win7_rtm.090713-1255)                                                                                                                                             

and if you want the attribute name and value on the same line format the output with format-list:

PS D:\> (get-item c:\windows\system32\write.exe).VersionInfo | select FileVersion | fl


FileVersion : 6.1.7600.16385 (win7_rtm.090713-1255)
Duncan
  • 92,073
  • 11
  • 122
  • 156
1

fl is an alias for format-list. In most cases, format commands should be used right before you output the results.

If you want to select specific properties you can do it with the '.'-operator. In your case:

(dir c:\windows\system32\dfc.exe).versioninfo.fileversion
toftis
  • 1,070
  • 9
  • 26