If you have ever needed to retrieve just a few small pieces of management information from one or more remote servers this tool, using Windows PowerShell is an easy way to do it. All the remote servers need installed is the Windows Management Instrumentation or WMI Service. That is installed by default and set to run automatically in most computers. You will need to make sure that the firewall ports are open for it. Generally speaking that is the remote administration exception in the Windows firewall.
I started by naming this function Get-ServerInfo and I have included a block comment that Windows uses PowerShell’s comment based help feature. If I load this into the shell and then I run Help on it, it will display a normally formatted help screen that includes a description, how to use the different perimeters, even examples for using this thing properly.
There is not a lot in here that you would need to change in order to have it query additional information, but I will show you how to do that. Let’s say that in addition to providing the ComputerName, BIOSerial number, OSVersion, OSbuild number, SPVersion, and OSArch, and ProArch, we also want to display the TotalPhysicalMemory that is installed in the computer. Over here I have done that. I have queried from WMI the Win32_ComputerSystem class. I can see that there is a total physical memory property that displays the amount of memory that is installed.
To include that information in my output all I need to do is come right to this location. I will create a new variable called $comp, because this is going to contain computer system information and the call to Get-WMIObject, providing the Win32_ComputerSystem class. To keep this nicely formatted in the accompanying article, I am going to add a little back tick here. That simply allows me to escape the carriage return, but it is important that the carriage return be the last thing on that line. If I click back up here I can see that I do not have any spaces or tabs. The ISE does not give you a way of displaying those hidden characters like spaces or tabs; you just have to be very careful. We will finish the command by providing the computer name which will already be contained in the computer variable.
I am basically just copying and pasting these lines, providing a new variable name, and the appropriate class name. That queries the information. Now I need to attach it to my output. I will add a semi-colon right here. I will have this display as RAM in the output and it is just comp. I need to get this property name, the easiest way to do that is just paste it in. Inside of this hash table I just need to make sure that each line, except the last one, ends in a semi-colon. That way all the information will come together in the right spot.
Let’s save this and now we will open up a new copy of the shell. Here in a new copy of the shell I will run Import-Module mytools, since that is what I named my module. I should be able to check for help on Get-ServerInfo, and it displays the help. Let’s just run Get-ServerInfo and we will just provide a single computer name and all the information displays properly. Including the amount of RAM that is installed, the property that I just added. This should be a nice easy tool for you to quickly modify and then even redistribute to your colleagues so they can use it as well.