Board logo

标题: [转载代码] [PowerShell每日技巧]获取DLL文件的版本信息(20131204) [打印本页]

作者: 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:
  1. Get-ChildItem c:\windows\system32\*.dll |
  2.   Select-Object -ExpandProperty VersionInfo |
  3.   Select-Object -Property FileName, Productversion, ProductName
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:
  1. Get-ChildItem c:\windows\system32\*.dll |
  2.   Add-Member -MemberType ScriptProperty -Name Version -Value {
  3.   $this.VersionInfo.ProductVersion
  4.   } -PassThru |
  5.   Select-Object -Property LastWriteTime, Length, Name, Version |
  6.   Out-GridView
"$this" is the object you are extending.
作者: PS2.0    时间: 2017-8-18 09:36

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

欢迎光临 批处理之家 ( Powered by Discuz! 7.2