จากบทความที่แล้ว ที่ได้เกริ่นสาเหตุของปัญหาไปแล้ว ว่ามี Program หลากหลายเวอร์ชันมากในการทดสอบ วันนี้ผมเลยได้ลองเขียน Code ในการหาไฟล์ .exe, ocx, dll ในโพลเดอร์ที่เก็บ Program ทั้งหมด ตาม Version ของลูกค้า และ ชื่อไฟล์ที่ต้องการทดสอบครับ โดย Code คร่าวออกมาเป็นประมาณนี้ครับ
Get-ChildItem 'C:\Users\Chatr_000\Desktop\SAD\KTCO(2.0)\Dlls'-recurse -Include *.exe, *.ocx, *.dll |
Where-Object {(($_.VersionInfo).FileVersion -eq '6.00.0004') -and ($_.Name -like '*cal*')} |
Select-Object -ExpandProperty VersionInfo |
Select-Object -Property @{l='ParentPath';e={Split-Path $_.FileName}},FileName, FileVersion, Productversion, ProductName |
Out-GridView
ผลลัพธ์ที่ได้ (ขอปิดชื่อไฟล์นิดนึง งานบริษัทและ)
และสุดท้าย คือ แก้พวกค่า Path หรือเงื่อนไขต่างๆ ให้รับข้อมูลจากผู้ใช้เองเลย จะได้ไม่ต้องมาแก้ Code บ่อยๆครับ ดังนี้
<#
"FindFilesbyVersion"
Author : Chatri Ngambenchawong
Website : https://naiwaen.debuggingsoft.com/
Facebook: https://www.facebook.com/pingkunga
Twitter : https://twitter.com/pingkunga
Date : 20-SEP-2014
File : FindFilesbyVersion
Purpose : FInd Files by Version Using Powershell
Version : 1
#>
"`n"
write-Host "---------------------------------------------" -ForegroundColor Yellow
$filePath = Read-Host "Please Enter Base Path to Search"
write-Host "---------------------------------------------" -ForegroundColor Yellow
$fileName = Read-Host "Please Enter File Name to Search"
write-Host "---------------------------------------------" -ForegroundColor Yellow
$fileVersion = Read-Host "Please Enter version to Search (format x.xx.xxxx)"
write-Host "---------------------------------------------" -ForegroundColor Yellow
"`n"
Get-ChildItem $filePath -recurse -Include *.exe, *.ocx, *.dll |
Where-Object {(($_.VersionInfo).FileVersion -eq $fileVersion) -and ($_.Name -like '*'+$fileName+'*')} |
Select-Object -ExpandProperty VersionInfo |
Select-Object -Property @{l='ParentPath';e={Split-Path $_.FileName}},FileName, FileVersion, Productversion, ProductName |
Out-GridViewต่อไปจะเป็นการลองใช้ Code ชุดนี้ ไปประยุกต์กับ C# ทำ Application เล็กๆกันครับ
Discover more from naiwaen@DebuggingSoft
Subscribe to get the latest posts sent to your email.



