Hi all
I need a powershell script that will scan all the exe and dll files and will print their .NETCore version.
It doesnt matter that I do, all I can find is the product version.
What am I doint wrong?
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"