# PS script for .NET Core Version

**URL:** <https://forums.powershell.org/t/ps-script-for-net-core-version/24609>\
**Category:** PowerShell Help\
**Created:** [August 21, 2024, 2:03pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609 "2024-08-21T14:03:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![seriouspike](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@seriouspike](https://forums.powershell.org/u/seriouspike)\
**Post date:** [August 21, 2024, 2:03pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/1 "2024-08-21T14:03:29Z")

</div>

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:

```auto
# 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"

```

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [August 21, 2024, 2:59pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/2 "2024-08-21T14:59:31Z")

</div>

Hello, please make sure to use the “Preformatted Text” button on your code so that it is appropriately formatted. You can also wrap your code in 3 backticks if you’re familiar with Markdown formatting.

---

<div class="post-metadata">

**Author:** ![seriouspike](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@seriouspike](https://forums.powershell.org/u/seriouspike)\
**Post date:** [August 21, 2024, 5:45pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/3 "2024-08-21T17:45:01Z")

</div>

Done as requested 🙂

Anyone please?

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [August 21, 2024, 8:43pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/4 "2024-08-21T20:43:15Z")

</div>

Well, it looks like the .NET method you’re using is doing what’s it’s supposed to do:

```auto
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($filepath)

```

Here’s Microsoft’s documentation about that method:  
[FileVersionInfo](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.fileversioninfo.getversioninfo?view=net-8.0#system-diagnostics-fileversioninfo-getversioninfo(system-string))  
I don’t see anything in there that claims that it would return what version of .NET is required to run that executable or dll.

I’m not even sure what exe/dll to test against on my computer, but the response from Mark Walker on this page looks like a different method to achieve this:

> <https://stackoverflow.com/questions/325918/how-to-find-out-which-version-of-the-net-framework-an-executable-needs-to-run>

---

<div class="post-metadata">

**Author:** ![seriouspike](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@seriouspike](https://forums.powershell.org/u/seriouspike)\
**Post date:** [August 21, 2024, 8:58pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/5 "2024-08-21T20:58:38Z")

</div>

Hi,  
Thanks for the reference!

They suggest using Notepad to search for text inside files, but that’s not a viable option for me since I need to scan thousands of files. There must be a way to do this using PowerShell. I really hope someone here knows how.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [August 21, 2024, 9:20pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/6 "2024-08-21T21:20:18Z")

</div>

Well not every exe and dll is written in dotNet.

You can call

```auto
$binary = [System.Reflection.Assembly]::LoadFrom("C:\Path\to\file.exe")
$binary.Version

```

If the first line errors out then it’s not using dotNet

---

<div class="post-metadata">

**Author:** ![seriouspike](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@seriouspike](https://forums.powershell.org/u/seriouspike)\
**Post date:** [August 22, 2024, 5:02am UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/7 "2024-08-22T05:02:25Z")

</div>

@neemobeer  
Unfortunately, this does not print the .NET Core version of a file.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/c/cc7c25fba67b0eb5f7c41275cef33af3f7238889.png)

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [August 22, 2024, 1:48pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/8 "2024-08-22T13:48:29Z")

</div>

It’s in $binary.customattributes

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [September 21, 2024, 1:49pm UTC](https://forums.powershell.org/t/ps-script-for-net-core-version/24609/9 "2024-09-21T13:49:21Z")

</div>

Closed on September 21, 2024, 1:49pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
