Getting installed .NET Framework versions remotely

One of our customers has been requested to uninstall certain .NET framework versions from their workstations: it had surfaced that the EVS IPDirector version that the they were running was incompatible with anything above .NET Framework 4.5.1…

Potentially over a hundred workstations had to be checked, but I have found a way to automate the process!

People have tried to solve this problem before, with varying degrees of success:
Some solutions on Stack Overflow simply would not work for us, as a typical Windows computer has multiple .NET versions installed and if the script returns you only one version number – that does not give us the whole picture.
Luckily, Joakim Svendsen has produced a great PowerShell script that trawls through the registry, getting the list of all installed versions of .NET framework and puts them into a *.csv file.
The script itself can be downloaded here , and can be used as follows:

Get-DotNet-Version.ps1 –ComputerName hostname

If you have a list of hostnames (hosts.txt) you can just replace ‘hostname’ with (gc hosts.txt), resulting in:

Get-DotNet-Version.ps1 –ComputerName (gc hosts.txt)

Powershell script usage

Sadly, the script did not work for my system straight away and I have been getting the following error in the excel file, instead of the .Net version:

Exception calling “OpenRemoteBaseKey” with “2” argument(s): “The network path was not found.”

As this StackOverflow question reveals the problem above comes from RemoteRegistry service being turned off. So let’s modify the PowerShell script to first enable RemoteRegistry service autostart and then actually start it, before trying to read any registry values. This can be easily done by adding a few lines:

Write-Host -Fore Green “Enabling RemoteRegistry service”
sc.exe \\$Computer config remoteregistry start= auto
sc.exe \\$Computer start remoteregistry

If the service is already running we will simply get an appropriate message:
PowerShell Script Running getting .Net versions

EDIT: Joakim has kindly added a separate section in his Wiki page, providing a script to enable and disable the Remote Registry service on a number of workstations!


The output of the script looks like this, indicating .NET versions that are installed on each host:
Getting .NET framework versions script output

We can now look at machines that are running .NET framework versions that are incompatible with our client application and uninstall them.
Due to the lack of time I didn’t manage to play with unattended/silent uninstalls on this occasion. But it doesn’t mean that you can’t! Here is a lovely list of silent repair and uninstall commands for your tinkering pleasure:

EDIT: I DID get some time to play with remote re-installs and you can read more about it here

And some extracts that pertain to our case:

.NET Framework 4.5.2 (32-bit) – silent uninstall
%windir%\Microsoft.NET\Framework\v4.0.30319\SetupCache\v4.5.51209\setup.exe /uninstall /x86 /x64 /q /norestart
.NET Framework 4.5.2 (32-bit) – unattended uninstall
%windir%\Microsoft.NET\Framework\v4.0.30319\SetupCache\v4.5.51209\setup.exe /uninstall /x86 /x64 /passive /norestart
.NET Framework 4.5.2 (64-bit) – silent uninstall
%windir%\Microsoft.NET\Framework64\v4.0.30319\SetupCache\v4.5.51209\setup.exe /uninstall /x86 /x64 /q /norestart
.NET Framework 4.5.2 (64-bit) – unattended uninstall
%windir%\Microsoft.NET\Framework64\v4.0.30319\SetupCache\v4.5.51209\setup.exe /uninstall /x86 /x64 /passive /norestart