Using WMIC to re-install .NET Framework versions remotely

In the previous post we have gathered a list of workstations that required their Microsoft .NET Framework to be downgraded. Let’s downgrade them remotely using the Windows Management Instrumentation Command-line (WMIC).

 

WMIC: Getting list of installed software remotely

To get a list of all installed software on a remote computer, we can use the Windows Management Instrumentation Command-line (WMIC) – a command-line and scripting interface that simplifies the use of Windows Management Instrumentation (WMI) and systems managed through WMI.

To enter the console, type in wmic in cmd.exe or PowerShell:
WMIC in Command Line

Then, we could execute the following command to list all software installed on the remote machine:

/node:”computername” product get name, version

WMIC list of installed software

If we are only interested in a particular piece of software we can filter this list by using LIKE clause. This is a great post on using it.

/node:”computername” product where “Name like ‘%NET%’” get Name, version

WMIC LIKE clause

 

WMIC: Uninstalling software remotely

To uninstall:

/node:”computername” product where name=”Microsoft .NET Framework 4.5.2″ call uninstall

And we get a successful uninstall (note how the software no longer appears in the list below):
WMIC successful uninstall

 

Preparing the installer

Installing our desired .NET version remotely is slightly more difficult, because when we call install method in wmic, it expects a suitable *.msi to be present on the remote machine local drive. While it’s relatively simple to copy the installer files to the remote machine, getting the offline .NET installer to work directly is not a trivial task.
ITNINJA will help us with that through this magnificent article.

I would recommend you to follow steps listed in the resource above, but in essence, we need to unpack the .NET 4.5.1 installer *.exe file, then patch the original MSI installer, so that it allows us to run it directly. I will only describe one thing that isn’t mentioned in the article. For our purposes within InstEd software we still have to modify the CA_BlockDirectInstall (as the article suggests):
Patching .NET Installer to allow direct install

But instead of just saving the transform as the article above suggests, we first save the transforms and then save the modified installer into the *.msi file by selecting Save Transformed option:
Saving InstEd transformed installer

 

WMIC: Installing software remotely
Save the *.msi into the folder with extracted installer contents and copy that folder to remote machine. Then, call the install method from wmic:

wmic:root\cli>/node:”computername” product call install true,””,”C:\DotNet\dotnet.msi”


WMIC successful install

Let’s check that we have indeed installed the desired software by getting the list of installed products again:
WMIC: checking list of products after install
Success!

 

WMIC: Restarting machines remotely

If the applications making use of .NET framework require a restart (they do in our case) you can also restart the machine using WMIC:

wmic:root\cli>/node:”computername” os where Primary=’TRUE’ reboot


WMIC remote restart reboot

 

Steps above could of course be easily automated and I may get some spare time in future to put together an appropriate script


1 Trackback