This script allows you to specify a WMI class and any properties that you wish to query, run the WMI query against every computer in an array of OUs (also allow you to exclude any child OUs that you do not wish to query). the Output is stored in a CSV file located on the same directory of the script.
The OUs and excluded OUs are hardcoded in the script and the WMI class, properties (optional) and WMI namespace (optional) are passed into the script as parameters. if no wmi class properties are specified, the scripts returns all properties from the class. if no namespace is specified, the default name space of "root\cimv2" is used.
Here are some sample commands to run the script:
.\WMIQuery.PS1 win32_service name, status
.\WMIQuery.PS1 DELL_Chassis assettag root\cimv2\dell
Unfortunately this script has to run under an account that has admin rights to all the machines (e.g. a domain admin account). because it uses [wmisearcher] accelerator rather than get-wmiobject cmdlet (which allows you to use an alternative credential). I had to use [wmisearcher] because get-wmiobject does not allow you to set a timeout for the WMI queries. - Please let me know if you know how to overcome this problem.