Quick Links
PowerShell is used by many server administrators.
Prerequisites
This article will be hands-on.
In practice what does something like this look like?
Let’s list out some of the properties that would be very useful to know.
Since we have a list of servers, we will have to iterate over the$Serversobject and query.
Starting with a simpleForeach-Objectloop below, we can create a custom object to hold our values.
Unfortunately, this is not all of the information that we need.
The second problem here is that we have more than one drive being returned.
I would like to know about each of those drives and how much free space is available in GBs.
Let’s modify the code to do some transformations and make it better.
After we trigger the commands, our output is much cleaner and can now be used in our script.
But what if we wanted to alert on a low disk space condition?
As you could tell now, we have a great set of information to be saved with our servers.
If you find that some are over-provisioned you could save valuable resources by right-sizing the servers.
Thankfully, this is much simpler to retrieve.
Using theWin32_PhysicalMemoryWMI class, we can sum all of the returnedCapacityproperties to get the total memory.
This is useful to know if a certain server has multiple interfaces to be worried about.
Our output will look similar to that below and we can then save this into our script.
Keep in mind that forInvoke-Commandto work, PS Remoting will need to be set up on the target servers.
There are many more useful properties that you’re free to add on to this report.
PowerShell makes it trivially easy to get all the information you should probably put together in one place.