Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This post covers basic provisioning operations against local Windows storage resources using the Storage module for Windows PowerShell.
Note: I will cover using the Storage module in combination with a Storage Management Provider to manage a storage subsystem (array) in a subsequent post.
The Disk, Partition, and Volume objects are associated as shown in the figure below. When starting from a new (blank) disk, you first initialize the disk to create a partition, and then you create a Volume with a file system such as NTFS.
The following sections discuss the operations that you can perform with each type of object – Disk, Partition, and Volume. They also discuss setting the policy of whether to automatically mount new disks, and how to use the various cmdlets to format a new disk for use.
A Disk object represents a disk as seen by a Windows computer, and does not require an available management provider. An example of a Disk object is a disk displayed in the Disk Management snap-in.
To list all Disks visible to the operating system, type:
Get-Disk
To list only the system disk, type the following command:
Get-Disk | Where-Object IsSystem -eq $True
To list all disks except the system disk, instead type this command, which pipes the output of the Get-Disk cmdlet to the Where-Object cmdlet:
Get-Disk | where-object IsSystem -eq $False
To list all disks attached via a specific storage bus, type the following command, replacing <BusType> with the bus you want to query:
Get-Disk | Where-Object -Eq <BusType>
For example, to list all of the Storage Spaces that are connected, query disks connected via the “Spaces” bus. This method can also be used for other bus types, such as iSCSI and USB:
To clear all partitions and volumes from a disk, backup all data on all volumes on the disk, and then type the following command:
Warning: This is operation cannot be undone; it will clear all partitions and volumes from the disk and allows the disk to be re-initialized and create a new partition and volume.
Clear-Disk 6 -RemoveData
Note: If the specified disk contains an OEM partition, such as for system recovery, it is also necessary to specify the –RemoveOEM switch when using the clear-disk cmdlet.
To initialize a disk to allow creation of a partition and volume, type the following command, where <DiskNumber> is the number of the disk to initialize:
Initialize-Disk <DiskNumber>
Note: All disks are initialized as GPT by default unless otherwise specified.
To initialize a disk as MBR, use the –PartitionStyle parameter. For example:
Initialize-Disk 4 –PartitionStyle MBR
To list all disks that are currently offline, type the following command:
Get-Disk | Where-Object IsOffline –Eq $True
To bring all disks that are currently offline back online, type the following command:
Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False
A Disk object can contain one or more logical regions called partitions, which are represented by a Partition object. With the exception of special purpose partitions such as a Microsoft Reserved (MSR), or OEM recovery partition, Microsoft recommends creating one data partition per disk.
To list all partitions on all disks, type the following command:
Get-Partition
To list all partitions on a specific disk, type the following command, replacing <DiskNumber> with the number of the appropriate disk:
Get-Partition –DiskNumber <DiskNumber>
To create a new partition on a blank disk, first use the Initialize-Disk cmdlet, then type the following command, replacing <DiskNumber> with the number of the appropriate disk:
New-Partition –DiskNumber <DiskNumber> -UseMaximumSize -AssignDriveLetter
A Volume object is the highest level object in the Disk-Partition-Volume hierarchy and represents a Partition object that has been formatted with a file system such as NTFS or ReFS and is available for data storage.
To list all volumes accessible to Windows, type:
Get-Volume
To list the volume for a specific drive letter, type the following, replacing <DriveLetter> with the letter of the drive you want to view:
Get-Volume –DriveLetter <DriveLetter>
To format a volume with the NTFS file system, type the following, replacing <DriveLetter> with the letter of the drive you want to format:
Format-Volume -DriveLetter <DriveLetter>
The new disk policy (previously known as the SAN Policy) is the policy Windows uses to determine whether Windows should automatically ‘mount’ disks that are detected as new.
To view the new disk policy, type the following command:
Get-StorageSetting | Select-Object NewDiskPolicy
To set the new disk policy, type the following command:
Set-StorageSetting –NewDiskPolicy OfflineShared
Note: The default setting for NewDiskPolicy on Windows 8 is OnlineAll. The default setting on all Windows Server 2012 editions is OfflineShared.
Policy Setting |
Effect |
OfflineAll |
All new disks are left offline by default. |
OfflineInternal |
All disks on busses that are detected as internal are left offline as default. |
OfflineShared |
All Disks on sharable busses, such as iSCSI, FC, or SAS are left offline by default |
OnlineAll |
All disks are automatically brought online. |
To format a new disk that has not been initialized, first we should get all Disk objects and then pipe the objects to the Where-Object cmdlet to select only disks with the RAW partition style (which indicates that the disks haven’t yet been initialized). To do so, type the following command:
Get-Disk | Where-Object PartitionStyle –Eq "RAW"
Then, use the Initialize-Disk cmdlet to initialize the disk. After that, use the New-Partition cmdlet to create a partition on the disk, and pipe the output to the Format-Volume cmdlet to format the volume with the NTFS file system. To do so, type the following commands:
Initialize-disk 3
New-Partition -DiskNumber 3 -UseMaximumSize -AssignDriveLetter | Format-Volume -NewFileSystemLabel "Mirror" -FileSystem NTFS
Bruce Langworthy
Senior Program Manager – Windows Storage and Filesystems
Please sign in to use this experience.
Sign in