« Previous 1 2
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.
Infos
- Dynamic disks: https://docs.microsoft.com/en-us/windows/win32/fileio/basic-and-dynamic-disks#dynamic-disks
- Connect-IscsiTarget: https://docs.microsoft.com/en-us/powershell/module/iscsi/connect-iscsitarget?view=windowsserver2022-ps
- Storage module help: https://docs.microsoft.com/en-us/powershell/module/storage/?view=windowsserver2022-ps
« Previous 1 2
Buy this article as PDF
(incl. VAT)