Manage Windows Server storage with PowerShell

Robots in the Data Center

Storage Spaces with PowerShell

Compared with the legacy Basic Disks and Dynamic Disks, Storage Spaces is a relatively new technology. It originated on Windows Home Server, which Microsoft used as a design study for how to provide fault-tolerant and high-performance storage volumes made up of inexpensive serial ATA (SATA) drives without having to resort to hard-to-manage and error-prone dynamic disks.

The Storage Spaces product was introduced in Server 2012 R2. The new Server Manager was intended for graphical management from the outset, which means that full PowerShell support must be available under the hood. This support is provided by the Storage module. The previously mentioned Get-Disk and Set-InitiatorPort commands also originate from this module, which has been expanded from 103 commands in Server 2012 to 160 commands in Server 2022, without changing the module version number.

If you want to create a new storage pool on your Windows system, start with the familiar cmdlet, but now add a parameter:

Get-PhysicalDisk -CanPool $true

If not all the disks you expected are listed, you can use

Get-PhysicalDisk -CanPool $false | ft DeviceId, CannotPoolReason

to output what is preventing specific disks from being added to a pool. Once you have eliminated the problems, create the new pool:

$sub = Get-StorageSubSystem -FriendlyName "Windows Storage*"
$disks = Get -PhysicalDisk -CanPool $true
$pool = New -StoragePool -FriendlyName '<Name>' -PhysicalDisks $disks-StorageSubSystemUniqueId $sub.UniqueId

In the pool now, enter

$pool | New -VirtualDisk -FirendlyName <Name>-Size <size>-ProvisioningType Thin -ResiliencySettingName Mirror -NumberOfDataCopies 2

to create a virtual disk with thin provisioning that has a RAID1-style level of protection (two copies of each block). Unlike the step-by-step wizard in Server Manager, the availability of the required number and size of disks is not checked until you submit the command, so it might experience a failure when you try to create the drive. The object created at the PowerShell pipeline is a Disk . You can pipe this to Initialize-Disk and then on to New-Partition and Format-Volume (as described at the beginning of this article) to create a formatted disk.

Like every more complex storage system, it is important to monitor the status of the drives and initiate repairs at an early stage. To help you do this, all objects returned by the Get-StoragePool, Get-VirtualDisk, Get-PhysicalDisk, or Get-Volume cmdlets have a HealthStatus property. If it does not read Healthy , you need to check the status of the individual components and eliminate any problems. Sometimes, however, logical errors creep in. Storage Spaces can usually fix these errors itself, provided the redundancy level you selected is sufficient to let it do so. You can initiate this process for all virtual disks with a PowerShell command:

Get-VirtualDisk | Where-Object {$_.HealthStatus -Eq "Unhealthy"} | Repair-VirtualDisk

The Repair-VirtualDisk cmdlet can also handle the -PassThru switch, which you can use to pipe the results of the repair. If the repair fails, you need to continue digging down to find the root cause.

Storage Spaces offer a variety of other features, such as tiered storage, enclosure management, and more. All these functions are fully supported by matching custom PowerShell cmdlets and additional parameters in the more general commands. In fact, the only management interface for Storage Spaces is PowerShell – both Server Manager and Windows Admin Center rely on PowerShell for graphical management.

Conclusions

Microsoft provides PowerShell modules [3] that enable automation of your storage provisioning and management. To leverage the maximum benefits, you need to learn about the Windows storage subsystem, and especially about its different modes of operation and the options for addressing disks. However, operations with traditional dynamic disks are no longer supported by PowerShell or WMI. For newer systems, you will want to opt for Storage Spaces, anyway, for which full PowerShell support is available.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Highly available Hyper-V in Windows Server 2016
    Microsoft has extended the failover options for Hyper-V in Windows Server 2016 to include two new cluster modes, as well as the ability to define an Azure Cloud Witness server. We look at how to set up a Hyper-V failover cluster.
  • Clusters with Windows Server 2012 R2
    With Windows, you can create a highly available cluster at the click of a button. The cluster will even handle fully automated, non-disruptive software upgrades.
  • Storage pools and storage spaces in Windows
    Storage spaces and storage pools combine a variety of storage technologies into a single logical unit, ensuring high availability and a choice of resiliency capability.
  • Dealing with VHDX files
    VHDX files introduce some improvements over the legacy virtual hard disk format. In this article, we review some of the interesting features.
  • Hyper-V with the SMB 3 protocol
    Microsoft has introduced several improvements to Windows Server 2012 and Windows Server 2012 R2 with its Server Message Block 3. Hyper-V mainly benefits from faster and more stable access to network storage. In this article, we look at the innovations.
comments powered by Disqus