Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Needed: PowerShell Script to Retrieve .NET Core Version for EXE and DLL Files

Status
Not open for further replies.

seriouspike

Programmer
Aug 21, 2024
1
Hi everyone,
I'm looking for a PowerShell script that can scan all the .exe and .dll files and output their .NET Core version. No matter what I try, I keep getting only the product version.
What am I doing wrong? Any help would be appreciated!

Below is the present script that I have:



# Define the paths to scan
$paths = @("C:\Program Files\Program1", "E:\Program2")

# Define the output CSV file path
$outputCsv = "C:\FileVersions.csv"

# Initialize an array to hold the file information
$fileInfoArray = @()

# Function to get .NET Core version from a file
function Get-DotNetCoreVersion {
param (
[string]$filePath
)
try {
$versionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($filePath)
return $versionInfo.ProductVersion
} catch {
return "Unknown"
}
}

# Scan the directories for .dll and .exe files
foreach ($path in $paths) {
Get-ChildItem -Path $path -Recurse -Include *.dll, *.exe | ForEach-Object {
$filePath = $_.FullName
$dotNetCoreVersion = Get-DotNetCoreVersion -filePath $filePath
$fileInfoArray += [PSCustomObject]@{
FilePath = $filePath
DotNetCoreVersion = $dotNetCoreVersion
}
}
}

# Export the file information to a CSV file
$fileInfoArray | Export-Csv -Path $outputCsv -NoTypeInformation

Write-Output "File information has been exported to $outputCsv"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top