How to inventory server storage with PowerShell

Performing IT storage inventories, especially on servers, is complex due to the number of factors involved. There can be multiple physical media devices each containing multiple logical volumes. Volumes can span multiple disks with hardware or software RAID configurations. Each volume can be configured with its own drive letter and file system folders can be shared on the network.

These inventories are important because collecting data on physical storage media can identify the type of storage available and the physical storage capacity of servers. PowerShell can help with these inventories, especially the Get-PhysicalDisk cmdlet, which uses Windows Management Instrumentation (WMI) under the hoods. Get-PhysicalDisk uses WMI to query the MSFT_PhysicalDisk class, where the WMI class provides numeric values ​​for things like MediaType and BusType, while Get-PhysicalDisk returns descriptive text values.

Like most PowerShell cmdlets, Get-PhysicalDisk only displays a very small subset of the information it returns by default. To coax all information, Get-PhysicalDisk | Select-Object * will provide the full story. It brings together many, many properties, but here we’ll focus on a handful that most people will find useful.

Manufacturer, FriendlyName and SerialNumber are all pretty self explanatory. Both MediaType and BusType are very useful as they will let you know if you are dealing with platter-based HDDs or SSDs, as well as what type of connection these drives use, such as SCSI, SATA, or NVMe. The Size property is another obvious win, but be aware that it’s returned in bytes, so it makes sense to convert it to GigaBytes to make it more user-friendly (either $_.Size/1024/1024/1024 or $_.Size / 1 GB as shown in the picture).

Obviously, the health of your storage is a huge issue because a failure can lead to downtime or even data loss if not anticipated and addressed, which is why the SMART system exists to help predict disk failures. SMART stands for Self-Monitoring, Analysis and Reporting Technology, and many factors and telemetries go into SMART scores. To streamline the return, Get-PhysicalDisk simply returns an overall health value. (How to retrieve more granular SMART details is covered later.)

Logical storage volumes are the logical storage space available to servers and are roughly the Windows equivalent of partitions, the main technical difference being that volumes can be designed to span multiple disks. There is some overlap between physical and logical storage, especially storage capacity and available space.

the Get-Volume The cmdlet lists Windows volumes, including drive letter, file system used (FAT32, exFAT, NTFS, etc.), volume name, and capacity details. The cmdlet can easily be exploited to list volumes with legacy file systems (Get-Volume | Where-Object FileSystem -notin ‘NTFS’, ‘exFAT’), volumes without a drive letter (Get-Volume | Where-Object DriveLetter -eq $null), or volumes with space remaining below a particular capacity threshold (Get-Volume | Where-Object {$_.SizeRemaining/$_.Size -lt .25}).

File shares (or network shares) are a common aspect of servers and can indicate that a server functions as a file server or potentially hosts one or more line-of-business applications. It’s good practice to check file shares from time to time. First, file shares tend to be essential to your business, either because of the systems and applications they support, or because of the files they contain that are vital to your users. Second, loss of business awareness and turnover in general – in terms of staff and business demands – can lead to abandonment of on-premises file shares. In either case, it’s important to keep track of them, either to better manage availability or to properly decommission shares that are no longer needed.

The well named Get-FileShare The cmdlet can retrieve file shares, but it has some somewhat annoying limitations, especially when trying to identify the local path corresponding to a share. It is better to use the Get-SmbShare Cmdlet, which includes key functional information such as Name and Path properties, as well as capability details such as ConcurrentUserLimit and CurrentUsers. It can also display the availability of Volume Shadow Copy Service (VSS), the set of interfaces to create a point-in-time bulk data backup. Get-SmbShare also provides the Special property that indicates whether a share is an integrated Windows share.

Each of these details has value for administrators and can be listed in the PowerShell console using Get-SmbShare | Format-Table ConcurrentUserLimit, CurrentUsers, Name, Path, Description, ShadowCopy, Special. To focus on a specific share, pass the -Name parameter, as in Get-FileShare -Name ‘BusinessFiles’.

Sharing permissions are a key part of business file sharing. PowerShell can help dig into share permissions using the Get-SmbShareAccess cmdlet. Get-SmbShareAccess requires naming one or more shares to assess (Get-SmbShareAccess -Name ‘Data’,’Software’) but to get a full list of permissions for all shares, use Get-SmbShareAccess -Name (Get-SmbShare | Select-Object – Expand Property name). This one-liner first lists the available shares by name (the code in parentheses is executed first), then passes the list to the parameter of the Get-SmbShareAccess cmdlet.

Going back to SMART telemetry, it can be used to provide telemetry data in detail, and the Get-StorageReliabilityCounter cmdlet is the tool to produce it.

We mentioned earlier that SMART telemetry can retrieve an overall health score for a physical disk, but what if you want to dig into that telemetry in detail and form your own opinion based on those metrics? Fortunately, PowerShell offers tools to acquire these disk metrics in the form of Get-StorageReliabilityCounter cmdlet.

SMART metrics apply to physical disks and require specifying the disk to scan or it will retrieve information about all disks. The easiest way to do this is to use Get-Disk | Get-StorageReliabilityCounter which starts with the Get-Disk cmdlet and redirects it to Get-StorageReliabilityCounter. To specify a specific disk, use one of many parameters (disk ID, friendly name, serial number, etc.). Additionally, SMART telemetry for a particular logical volume can be obtained by chaining together multiple cmdlets: Get-Volume -DriveLetter C | Get-Partition | Get-Disk | Get-StorageReliabilityCounter. There are a lot of hoops to jump through, which have to do with the type of values ​​each cmdlet accepts as input parameters. Disk health information retrieved in this way includes read and write errors, latency, temperature, and even the number of hours the disk has been powered on.

Join the Network World communities on Facebook and LinkedIn to comment on the topics that matter to you.

Copyright © 2022 IDG Communications, Inc.