PowerShell for Storage and File System Management (Part 1)

If you would like to read the other parts in this article series please go to:

Recently I have been spending quite a bit of time working with Windows Server storage. In doing so, I have found that PowerShell works surprisingly well for both storage management and for file system management. That being the case, I thought that it might be fun to write an article series discussing some of the many storage related tasks that can be performed through PowerShell.

So with that said, let’s start with something simple. Let’s check the health of our physical disks.

There are a number of different ways to perform a disk health check. The easiest method involves using this command:

Get-PhysicalDisk | Select-Object FriendlyName, HealthStatus

Image
Figure A: We have retrieved disk health information.

As you can see in Figure A, this command makes it easy to tell whether or not the disks in your server are healthy. Now obviously that’s a great start, but if I were to be brutally honest then the command shown above is of limited value for several different reasons.

For starters, the command shown above has to be run manually. The command would be a lot more effective if it were scheduled to run automatically several times each day and then report any problems to the administrator. Fortunately, this is something that we can do without too much effort.

Another problem with the command that is shown above is that the output is somewhat vague. OK, our disks are healthy. That’s great. But what if they weren’t? What if the command’s output told us that PhysicalDisk2 was unhealthy?

In that sort of situation then we would probably have more questions than answers. What does a status of unhealthy even mean? Has the disk failed or does it merely need some sort of corrective action? If the disk has failed then where is the disk located? After all, the name PhysicalDisk2 is relatively meaningless.

My point is that while it is nice to be able to detect storage problems, it is even more important to be able to gather meaningful information about the problem. Thankfully, PowerShell can provide us with a lot more information about the disks in our server.

To give you a better idea of the types of information that we can gather, there are two commands that I want to show you. The first command is very similar to the command that you have already seen. This command is:

Get-PhysicalDisk | Where FriendlyName –eq PhysicalDisk0 | Select-Object *

This command, which you can see in Figure B, is designed to show you all of the various objects that can be displayed for a physical disk. I have used the Where FriendlyName – EQ PhysicalDisk0 command as a way of limiting the results to a single disk. The reason why I have done this is because all of the disks have the same object names and I didn’t want the command output to become long and repetitive.

Image
Figure B: These are the object names that are associated with physical disks.

As you look at the figure above, you will see that PowerShell exposes a number of different objects for each virtual hard disk. If we are interested specifically in the disk’s health then some of the more useful objects are OperationalStatus and HealthStatus.

Once again, these two objects really don’t provide us with very much information. Even so, there are some other things that we can do. Let’s suppose for a moment that the disk’s health status came back as unhealthy. If we were to determine that the disk was completely dead then it would be helpful to know where the disk is physically located. We could retrieve this information by using objects such as EnclosureNumber, SlotNumber, Manufacturer, Model, and SerialNumber. Of course if you look at the previous figure you will notice that these particular objects are empty. The reason for this is that I am working in a lab environment and am not using true server class disks. Normally however, these objects would contain information that would help you to locate the physical disk.

I mentioned a moment ago that there was another command that could help us to retrieve physical disk health information. This command is Get-StorageReliabilityCounter.

If you try running the Get-StorageReliabilityCounter cmdlet by itself you will receive an error message. In order to use this command, you will have to first enter the Get-PhysicalDisk command. For instance, if I wanted to see the storage reliability information for physical disk 2, I could enter the following command:

Get-PhysicalDisk | Where FriendlyName –EQ PhysicalDisk2 | Get-StorageReliabilityCounter | Select-Object *

Just to break down the command a little bit, the first part (Get-PhysicalDisk) retrieves a list of physical disks. The second part of the command (Where FriendlyName –EQ PhysicalDisk2) filters the results so that information is shown only for PhysicalDisk2. The third part of the command (Get-StorageReliabilityCounter) retrieves reliability data for the disk, and the last part of the command (Select-Object *) causes PowerShell to display every available reliability object. You can see these objects in Figure C.

Image
Figure C: These are the storage reliability counter objects.

As you look at the figure above, you will see that there is some reliability information that is relatively meaningless. However, there are also some very handy usage statistics. For example, we can see read and write errors in terms of total errors, corrected errors, and uncorrected errors. We can also see the drive’s temperature and the amount of disk wear. We can even see the maximum read and write latency as well as the number of hours that the disk has been in use.

So how can we put this data to work? Well, one option would be to create a basic health status report and then if any of the disks are reported as unhealthy produce a report that shows the disk’s various statistics as well as its location. That is certainly one option. In fact, I am going to show you how to do this in the next article in this series.

Another option is to be proactive with regard to monitoring disk health. At the beginning of this article, I showed you a simple command that would report whether each disk is healthy or unhealthy. However, we can look at things other than (or in addition to) a disk’s health status. Perhaps we would like to be notified if a disk experiences an excessive number of read errors. Maybe we want to know that there is a problem if a disk gets too hot. The point is that we can use PowerShell to test for any condition that we want and we can also automate the script and even build in administrative alerts.

Conclusion

In the next article in this series, I will show you how to build a storage health report that provides basic health information, but also provides extra information if a problem is found. As we move forward, I will show you how to automate the script, how to build in administrative alerts, and how to test for a variety of conditions.

If you would like to read the other parts in this article series please go to:

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top