I was having a conversation with a colleague the other day about the many different ways to use Powershell and get-wmiobject to quickly tap into any WMI Class without having to source the work to vbscript. Gwmi gives you the opportunity to specify parameters and allow one to quickly attach to a remote PC or server and gather information about any class. Here is an example which will allow you to step through a given class on a remote computer and display the results to console.
- Lets step through first and then provide the command line:
- Open up command line > start > run > type in “cmd” and click on “OK”
- type in “Powershell” and press enter
- type in “gwmi -computer remoteHostname” without the quotes and press enter. The -computer parameter will allow us to specify the host we want to attach to.
- You will now be prompted to enter a class. For this example type in “win32_computersystem” and press enter
- Assuming the account you are using has rights to the remote computer/server, you will be displayed with information pertaining to the Win32_computersystem class (domain, manufacturer, model, name, primary owner name, total physical memory).
- Now if you dont want to step through the code, simply key in the following command at the PS> prompt.
- gwmi -class Win32_ComputerSystem -computer remotehostname
- gwmi -class Win32_ComputerSystem -computer remotehostname -credential domain\LanID <– this will allow you to specify a specific user account to authenticate against.
Combining Powershell and WMI can be very useful. Add a dash of a hashtable and loop though a series of hosts and you have a recipe for a great looking script.