Tiny Deathstars of Foulness

I recently needed to check and see whether a backup drive (which was just a 4TB USB drive) was plugged into a server. But the server had no GUI, so I had to use the command line. There was no drive letter mapped to this drive, so I needed to use something else and I needed to make a script that could be used long-term. Luckily, PowerShell can be used to obtain WMI information on the hardware installed on a computer. This allows administrators to query WMI about the USB devices currently installed on a server. In the following command, we’re going to use gwmi from PowerShell and we’re going to query for Win32_USBControllerDevice. We’re going to run the command against the computer name in question (example here is although if we left the -computername option off it would run against the host the command is run on). Get-WMiObject Win32_USBControllerDevice -computername | fl Antecedent,Dependent This will apply a filter, similar to using grep in bash. That filters only the antecedent and dependent fields from the computer. You could also remove the pipe and pull a full export, but if I’m using this in a script the less data to parse the better. If you think of WMI as containing a big tree about the hardware installed, the filter for Antecedent brings back what must be running in order for the drive to be present and the Dependent returns those that are dependent on the drive. You can also obtain a lot more information through WMI. For example, you can pull information from any of the WMI classes, such as win32_bios Get-WmiObject win32_bios -computername Note, you can derive properties and methods for a given class by using the get-member commandlet: Get-WmiObject win32_bios | get-member Once you know which property you need, you can then parse the information a little further to get a very specific answer: get-wmiobject win32_bios -computername | Select-Object displayname Finally, you can shorten this by replacing the Get-WmiObject commandlet with gwmi, which is an alias for that command. Test it out, if you like: gwmi win32_bios | get-member

March 28th, 2014

Posted In: Windows Server, Windows XP

Tags: , , , ,

It is not uncommon to end up with a number of shares on a server, be it Windows, Mac OS X or Linux. With all of this sprawl it can be useful to see the shares in a quick and concise manner. using the Win32_Share WMI class through PowerShell you can do just that from the command line, similar to the sharing command in Mac OS X Server. The command, from PowerShell would be something similar to the following:
get-WmiObject -class Win32_Share
Assuming communication is working as intended, you can also query for the shares of other systems, by adding a -computer switch and specifying the host you’re listing shares on, as follows:
get-WmiObject -class Win32_Share -computer
One can also list shared printers with a little trickeration in the {} side of things: get-WmiObject -list | where {$ -match “Printer”}

August 18th, 2009

Posted In: Active Directory, Windows Server

Tags: , , , ,