我需要讀取位于 zip 中的每個 dll 和 exe 檔案的所有檔案版本。這就是我到目前為止所擁有的。我能夠保存一個 dll,但該物件沒有 .fileversion
$vips = Get-ChildItem -path C:\_Projects\temp\Patch_1296247.vip
$checkfiles= "*.dll"
#C:\_Projects\temp\Patch_1296247.vip
foreach ($file in $vips) {
try {
$zip = [System.IO.Compression.ZipFile]::Open($file, "Read")
}
catch {
Write-Warning $_.Exception.Message
continue
}
$dlls = $zip.Entries.Where({ $_.Name -like "*.dll" })
foreach($dll in $dlls) {
$dll.FileVersion
$zip.Dispose()}}
dll只有那些屬性

如果我運行這一行,我可以獲得 dll 版本。也許是因為它不在 ZIP 中?如何將它添加到我的腳本中?
(Get-Item C:\_Projects\temp\Patch_1296247\ADWalk_4.0.0.101\JobAdWalk\AdWalk\a.Client.ServicesProvider.dll).VersionInfo.FileVersion
像這樣寫if可以嗎?我想用 1.0.0.0 和 0.0.0.0 列印所有 dll 我知道所有 dll 都可以,盡管它們都使用 1.0.0.0 或 0.0.0.0 (($dll.VersionInfo) -eq "1.0.0.0") -- > 假的?!?!
foreach ($file in $vips) {
try {
$zip = [System.IO.Compression.ZipFile]::ExtractToDirectory($file, $tempFolder)
$dlls = Get-ChildItem $tempFolder -Include "*.dll","*.exe" -Recurse
foreach($dll in $dlls) {
#$dll.VersionInfo
if (($dll.VersionInfo) -eq "1.0.0.0" -or "0.0.0.0")
{
write-host
Write-host "The version of $($dll.Name) is wrong!!!" -ForegroundColor Red
}
else {write-host "All dlls are ok"}
}
}
uj5u.com熱心網友回復:
您的$dll示例中有System.IO.Compression.ZipArchiveEntry型別。這種型別沒有VersionInfo屬性。該屬性是System.IO.FileInfo型別的成員。因此,您首先需要將壓縮檔案轉換為System.IO.FileInfo型別,然后才能讀取您的屬性。
例如,您可以通過將存檔提取到臨時目錄然后清理來做到這一點:
$vips = Get-ChildItem -path C:\_Projects\temp\Patch_1296247.vip
$checkfiles= "*.dll"
$tempFolder = "c:\temp\tempzip"
foreach ($file in $vips) {
try {
$zip = [System.IO.Compression.ZipFile]::ExtractToDirectory($file, $tempFolder)
$dlls = Get-ChildItem $tempFolder "*.dll"
foreach($dll in $dlls) {
$dll.VersionInfo
}
}
catch {
Write-Warning $_.Exception.Message
continue
}
finally {
Remove-Item $tempFolder -Force -Recurse
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/437591.html
標籤:电源外壳
上一篇:匯出顯式ACL權限
