Unable to open SQL Server Configuration Manager. When I click on Configuration manager I get the error: Cannot connect to WMI provider

I rdp’d to the sql server and to check which sql services are installed on the server – I tried to open SQL Configuration manager but I was unable to open SQL Server Configuration Manager. When I clicked on Configuration manager I get the error: Cannot connect to WMI provider.
You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager.

The first thing I did was to check if I have admin rights to the server.

How to fix the WMI Provider Error:
Open a command prompt in the location machine (run as administrator)
Then run the following command according to the SQL Server version which was installed on the machine.

SQL Server 2005
mofcomp “%programfiles(x86)%\Microsoft SQL Server\90\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2008 / R2
mofcomp “%programfiles(x86)%\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2012
mofcomp “%programfiles(x86)%\Microsoft SQL Server\110\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2014
mofcomp “%programfiles(x86)%\Microsoft SQL Server\120\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2016
mofcomp “%programfiles(x86)%\Microsoft SQL Server\130\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2017
mofcomp “%programfiles(x86)%\Microsoft SQL Server\140\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2019
mofcomp “%programfiles(x86)%\Microsoft SQL Server\150\Shared\sqlmgmproviderxpsp2up.mof”

SQL Server 2022
mofcomp “%programfiles(x86)%\Microsoft SQL Server\160\Shared\sqlmgmproviderxpsp2up.mof”

If you run the above script for the correct sql version that is installed on your server then you will get the following message:

Hope this helps people resolve the issue they get when they try to open SQL Server configuration manager and get a WMI error.