PowerShell에서 파일 버전 가져 오기
PowerShell 의 .dll또는 .exe파일에서 버전 정보를 어떻게 얻을 수 있습니까?
나는 특별히에 관심이 File Version다른 버전 정보 (즉,하지만, Company, Language, Product Name, 등)뿐만 아니라 도움이 될 것입니다.
PowerShell은 .NET 클래스 를 호출 할 수 있으므로 다음을 수행 할 수 있습니다.
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("somefilepath").FileVersion
get-childitem * -include *.dll,*.exe | foreach-object { "{0}`t{1}" -f $_.Name, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).FileVersion }
또는 스크립트로 더 좋을 수도 있습니다 : http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!125.entry
요즘 Get-Item 또는 Get-ChildItem에서 FileVersionInfo를 가져올 수 있지만 업데이트 된 버전이 아니라 배송 된 제품의 원본 FileVersion이 표시됩니다. 예를 들어 :
(Get-Item C:\Windows\System32\Lsasrv.dll).VersionInfo.FileVersion
흥미롭게도 다음 을 사용하여 업데이트 된 (패치 된) ProductVersion 을 얻을 수 있습니다 .
(Get-Command C:\Windows\System32\Lsasrv.dll).Version
"original"과 "patched"의 차이점은 기본적으로 FileVersion이 계산되는 방식 때문입니다 ( 문서 참조 ). 기본적으로 Vista 이후 Windows API GetFileVersionInfo는 언어 중립 파일 (exe / dll)에서 버전 정보의 일부를 쿼리하고 언어 별 mui 파일에서 수정되지 않은 부분 (파일이 변경 될 때마다 업데이트되지 않음)을 쿼리합니다. ).
그래서 LSASRV 같은 파일을 사용하여 (인해 SSL / TLS 보안 문제로 대체되었다 / RDS 2014 년 11 월) 버전은 달랐다하고 (해당 날짜 이후에 적어도 동안) 이들 두 명령에 의해보고 된 두 번째 하나 는 IS 더 "올바른"버전.
그러나 LSASrv에서는 정확하지만 ProductVersion과 FileVersion이 다를 수 있습니다 (사실 공통적 임). 따라서 어셈블리 파일에서 업데이트 된 Fileversion을 바로 얻는 유일한 방법 은 다음과 같이 파트에서 직접 빌드하는 것입니다.
Get-Item C:\Windows\System32\Lsasrv.dll | ft FileName, File*Part
또는 여기에서 데이터를 가져 와서 :
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName)
PowerShell에서 TypeData를 업데이트하여 모든 FileInfo 객체에 쉽게 추가 할 수 있습니다.
Update-TypeData -TypeName System.IO.FileInfo -MemberName FileVersion -MemberType ScriptProperty -Value {
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($this.FullName) | % {
[Version](($_.FileMajorPart, $_.FileMinorPart, $_.FileBuildPart, $_.FilePrivatePart)-join".")
}
}
이제 당신이 할 때마다 Get-ChildItem또는 업데이트 된 FileVersion을 보여주는 속성을 Get-Item갖게 될 것입니다 FileVersion...
'dir'은 VersionInfo가 속성 인 파일 시스템에서 System.IO.FileInfo 클래스를 호출 할 때 System.IO.FileInfo 클래스를 반환하는 Get-ChildItem의 별칭입니다. 그래서 ...
단일 파일의 버전 정보를 얻으려면 다음을 수행하십시오.
PS C:\Windows> (dir .\write.exe).VersionInfo | fl
OriginalFilename : write
FileDescription : Windows Write
ProductName : Microsoft® Windows® Operating System
Comments :
CompanyName : Microsoft Corporation
FileName : C:\Windows\write.exe
FileVersion : 6.1.7600.16385 (win7_rtm.090713-1255)
ProductVersion : 6.1.7600.16385
IsDebug : False
IsPatched : False
IsPreRelease : False
IsPrivateBuild : False
IsSpecialBuild : False
Language : English (United States)
LegalCopyright : © Microsoft Corporation. All rights reserved.
LegalTrademarks :
PrivateBuild :
SpecialBuild :
여러 파일의 경우 :
PS C:\Windows> dir *.exe | %{ $_.VersionInfo }
ProductVersion FileVersion FileName
-------------- ----------- --------
6.1.7600.16385 6.1.7600.1638... C:\Windows\bfsvc.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\explorer.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\fveupdate.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\HelpPane.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\hh.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\notepad.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\regedit.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\splwow64.exe
1,7,0,0 1,7,0,0 C:\Windows\twunk_16.exe
1,7,1,0 1,7,1,0 C:\Windows\twunk_32.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\winhlp32.exe
6.1.7600.16385 6.1.7600.1638... C:\Windows\write.exe
PowerShell 커뮤니티 확장 을 설치하고 제공하는 Get-FileVersionInfo 함수 만 사용하는 것이 좋습니다.
이렇게 :
Get-FileVersionInfo MyAssembly.dll
다음과 같은 출력으로 :
ProductVersion FileVersion 파일 이름 -------------- ----------- -------- 1.0.2907.18095 1.0.2907.18095 C : \ Path \ To \ MyAssembly.dll
나는 그것을 전체 성공 디렉토리에 대해 사용했다.
Just another way to do it is to use the built-in file access technique:
(get-item .\filename.exe).VersionInfo | FL
You can also get any particular property off the VersionInfo, thus:
(get-item .\filename.exe).VersionInfo.FileVersion
This is quite close to the dir technique.
I realise this has already been answered, but if anyone's interested in typing fewer characters, I believe this is the shortest way of writing this in PS v3+:
ls application.exe | % versioninfo
lsis an alias forGet-ChildItem%is an alias forForEach-Objectversioninfohere is a shorthand way of writing{$_.VersionInfo}
The benefit of using ls in this way is that you can easily adapt it to look for a given file within subfolders. For example, the following command will return version info for all files called application.exe within subfolders:
ls application.exe -r | % versioninfo
-ris an alias for-Recurse
You can further refine this by adding -ea silentlycontinue to ignore things like permission errors in folders you can't search:
ls application.exe -r -ea silentlycontinue | % versioninfo
-eais an alias for-ErrorAction
Finally, if you are getting ellipses (...) in your results, you can append | fl to return the information in a different format. This returns much more detail, although formatted in a list, rather that on one line per result:
ls application.exe -r -ea silentlycontinue | % versioninfo | fl
flis an alias forFormat-List
I realise this is very similar to xcud's reply in that ls and dir are both aliases for Get-ChildItem. But I'm hoping my "shortest" method will help someone.
The final example could be written in long-hand in the following way:
Get-ChildItem -Filter application.exe -Recurse -ErrorAction SilentlyContinue | ForEach-Object {$_.VersionInfo} | Format-List
... but I think my way is cooler and, for some, easier to remember. (But mostly cooler).
This is based on the other answers, but is exactly what I was after:
(Get-Command C:\Path\YourFile.Dll).FileVersionInfo.FileVersion
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("Path\To\File.dll")
I find this useful:
function Get-Version($filePath)
{
$name = @{Name="Name";Expression= {split-path -leaf $_.FileName}}
$path = @{Name="Path";Expression= {split-path $_.FileName}}
dir -recurse -path $filePath | % { if ($_.Name -match "(.*dll|.*exe)$") {$_.VersionInfo}} | select FileVersion, $name, $path
}
As EBGreen said, [System.Diagnostics.FileVersionInfo]::GetVersionInfo(path) will work, but remember that you can also get all the members of FileVersionInfo, for example:
[System.Diagnostics.FileVersionInfo]::GetVersionInfo(path).CompanyName
You should be able to use every member of FileVersionInfo documented here, which will get you basically anything you could ever want about the file.
Here an alternative method. It uses Get-WmiObject CIM_DATAFILE to select the version.
(Get-WmiObject -Class CIM_DataFile -Filter "Name='C:\\Windows\\explorer.exe'" | Select-Object Version).Version
참고URL : https://stackoverflow.com/questions/30686/get-file-version-in-powershell
'IT' 카테고리의 다른 글
| 자바 스크립트에서 시간 지연을 설정하는 방법 (0) | 2020.06.24 |
|---|---|
| "종속성 분석"에 머물고있는 Cocoapods (0) | 2020.06.24 |
| Java에서 Enum 켜기 (0) | 2020.06.24 |
| 파일 키보드 바로 가기의 IntelliJ 시작 (0) | 2020.06.24 |
| 링크가 새 창을 열도록하십시오 (탭 아님). (0) | 2020.06.24 |