And another good day to everyone!
It has been busy for me, busier than it has been in a few years now. While it can annoy, it still is a good sign so I am hoping it will stay this busy.
Anyhow, that of course is not the reason I made this post. Today will be all about checking physical disks and their RAID status through Powershell.
This will mostly focus on 2 scripts. One to check the status of the physical disks and one to check the status of any RAID setups (If available).
The first one will check the health status of the disks and report back any issues.
To retrieve the status of the disks, we use the get-physical disk command.
Because we try to get results from the command whereby the status would be not healthy, it will only have output in $disks if there was a disk unhealthy.
Therefor if it contains anything, it will output it as being a possible disk failure together with the collected output.
If it contains nothing and the command did not encounter any errors, everything must have been on Healthy.
The output after a possible disk error has been encountered can be output towards either a log, event log or any other way of outputting the data.
For the second part, we will use diskpart.
The diskpart command can be used in CMD as well. As we want the best formatted output, we will use Powershell for this.
First, we use diskpart to get a list of disks and their state. Followed by a regular expression which filters out any removable and/or not applicable disk.
This is quite a big regular expression which ends up with only local physical disks that have a chance to be part of a RAID setup.
We can find more on regular expressions in these guides
After that point, it checks the lines for specific statuses.
Depending on the status of the disks, it pastes this in the status variable.
The status variable is then used to filter out the good statuses and output an error if needed.
Theoretically, the filtering would be needed if we did not match the Healthy status a bit earlier and setting up a Disk property.
However, these are all handy to have set up in the script already as adjustments can be made to make use of them which can lead to better formatted outputs.
Hopefully, this will give some people new ideas to add to automatic checks and/or other implementations.
Categories: Windows, Powershell, Script, Disk
Patrick Berger AKA Powershellder.
[ i ] Parallax section below. Click on the section below to upload image. Don't worry if it looks weird in the Weebly editor. It'll look normal on your published site.
To edit or delete your image, press the "toggle" button below. Then, hover over your image until a popup appears with the "edit" and "delete" options. If you don't want a white content section, leave it blank. It will disappear on your live website.