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"
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"