How to Return Versions of .NET Framework on a Machine using PowerShell Script

  1. Checking .NET Framework Version using PowerShell
  2. Conclusion
  3. FAQ
How to Return Versions of .NET Framework on a Machine using PowerShell Script

If you’re a developer or system administrator, knowing the version of the .NET Framework installed on your machine can be crucial for troubleshooting and ensuring compatibility with applications. Fortunately, PowerShell offers a straightforward way to check this information.

In this tutorial, we will guide you through the process of returning .NET Framework versions using PowerShell scripts. Whether you’re working on a Windows server or a local machine, this guide will equip you with the necessary commands to retrieve the version details quickly. So, let’s dive in and simplify your .NET Framework version checks!

Checking .NET Framework Version using PowerShell

PowerShell is a powerful scripting language that allows you to automate tasks and manage configurations effectively. When it comes to checking the .NET Framework version, you can utilize a simple command that queries the registry. This method is efficient and works across various Windows versions.

Method 1: Querying the Registry

To find out the installed .NET Framework versions on your machine, you can query the Windows Registry. The following PowerShell command retrieves the necessary information from the registry keys where .NET Framework versions are stored.

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | 
    Get-ItemProperty -Name Version -ErrorAction SilentlyContinue | 
    Where-Object { $_.Version -match '^\d+\.\d+' } | 
    Select-Object PSChildName, Version

Output:

v4.8.04084  4.8.04084
v4.0.30319  4.0.30319
v3.5       3.5.30729.4926
v2.0.50727  2.0.50727.4927

This command does the following:

  1. It navigates to the registry path where .NET versions are stored.
  2. It retrieves properties from the registry items, specifically looking for the “Version” property.
  3. It filters out results to show only those entries that match the version format.
  4. Finally, it selects the child name and version for display.

This method is particularly useful because it gives you a clear list of all .NET Framework versions installed on your machine, including major and minor versions.

Method 2: Using PowerShell to Check for .NET Core

If you are also interested in checking for .NET Core versions, you can run a different command. .NET Core installations are typically found in a different location, and the following command will help you retrieve that information.

dotnet --list-sdks

Output:

2.1.300 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]
5.0.203 [C:\Program Files\dotnet\sdk]

This command utilizes the .NET Core CLI to list all SDKs installed on your machine. Here’s how it works:

  1. The dotnet command is executed with the --list-sdks option.
  2. It returns a list of installed SDKs along with their respective paths.

This method is particularly beneficial for developers working with .NET Core, as it provides a quick overview of the SDKs they can use for their projects.

Conclusion

In this article, we explored how to return versions of the .NET Framework on your machine using PowerShell scripts. We covered two main methods: querying the registry for .NET Framework versions and using the .NET Core CLI to check for installed SDKs. Both methods are straightforward and can significantly streamline your workflow when managing .NET applications. By leveraging PowerShell, you can quickly ascertain the installed versions and ensure compatibility with your development projects.

FAQ

  1. How do I find out if .NET Framework is installed on my machine?
    You can use PowerShell to query the registry for installed .NET Framework versions.

  2. Can I check .NET Framework versions on remote machines?
    Yes, you can use PowerShell remoting to execute the same commands on remote machines.

  3. What is the difference between .NET Framework and .NET Core?
    .NET Framework is primarily for Windows applications, while .NET Core is cross-platform and suitable for various operating systems.

  4. Is PowerShell required to check .NET Framework versions?
    While PowerShell is a convenient method, you can also check the versions manually through the Windows Registry Editor.

  5. How can I update my .NET Framework version?
    You can download the latest version from the official Microsoft website and follow the installation instructions.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website