There are many scripts to get WMI data in the internet, but this script will use a unique technique. It will try getting remote data using many methods, preferring new ones and falling back to old legacy ones.
What is unique about this script is the amount of customization you can do with it. You can customize it completely just by adding one the script parameters and you are done.
If you run the script using -verbose mode, you will be presented with the right information for you to discover the power and logic of the script. Running the script by its own will not do anything as it is a wrapper function for you to use in other places where you need to get WMI data.
The script will basically get computer name or names, try to collect WMI information from them.
The script is smart enough to test if the remote computer is running PowerShell 3.0 at least and supports WS-MAN 3.0. If this is the case, the script will try to get WMI information by creating CIM session (Get-CIMSession).
If the script cannot connect to remote computer using CIM Session, then PowerShell remoting will be tried. If this fails too, the script will try to fall back to RPC call to get WMI data.
Version 2 of the script
After a quick chat with Jeffery Hicks (@JeffHicks) who i based my script upon his own version, Jeff suggested couple of modifications on my version of the script, specifically the concept of always returning objects instead of strings or other types. After tweaking the script to do that and add more verbose and exception additional information, i came with version 2 of the script.