批处理之家's Archiver

DAIC 发表于 2013-12-5 13:35

[PowerShell每日技巧]获取DLL文件的版本信息(20131204)

Ever needed a list of DLL files and their versions? Get-ChildItem can get this information for you. You just need to unpack some properties like so:[code]Get-ChildItem c:\windows\system32\*.dll |
  Select-Object -ExpandProperty VersionInfo |
  Select-Object -Property FileName, Productversion, ProductName[/code]This actually replaces (-ExpandProperty) the original FileInfo object with the VersionInfo object found within. You basically exchange one object for another one, and lose access to the information held in the first. For example, you no longer have access to properties like LastWriteTime.

If you'd rather want to keep the original FileInfo object, but add some additional information from inside, use Add-Member like this:[code]Get-ChildItem c:\windows\system32\*.dll |
  Add-Member -MemberType ScriptProperty -Name Version -Value {
  $this.VersionInfo.ProductVersion
  } -PassThru |
  Select-Object -Property LastWriteTime, Length, Name, Version |
  Out-GridView[/code]"$this" is the object you are extending.

[url=http://powershell.com/cs/blogs/tips/archive/2013/12/04/getting-dll-file-version-info.aspx]http://powershell.com/cs/blogs/tips/archive/2013/12/04/getting-dll-file-version-info.aspx[/url]

PS2.0 发表于 2017-8-18 09:36

[code](Get-ChildItem 'C:\Windows\System32\version.dll' | Select-Object -ExpandProperty VersionInfo).ProductVersion[/code]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.