
Getty Images
Top PowerShell disk management commands for Windows storage
These PowerShell cmdlets and scripts simplify Windows Server storage management by displaying existing storage information and creating or removing disk resources.
Managing storage capacity is one of the most crucial parts of system administration. PowerShell offers administrators many options for investigating and configuring storage options. This article examines the most useful cmdlets for viewing storage information, creating new storage space or removing unneeded storage capacity.
Shell environments offer administrators two advantages:
- Command-line commands are often quicker to enter and run than browsing through multiple windows and consoles in mouse-driven environments.
- Commands can be added to scripts, enabling you to schedule automated tasks.
You certainly have the option of running individual commands directly from the PowerShell console. However, you might find it more efficient to script your configurations as part of a larger infrastructure-as-code initiative. Keep this option in mind as you review the cmdlets below.
PowerShell syntax review
Recall that PowerShell uses a verb-noun syntax to specify tasks. These two combined elements are called cmdlets and form the basis of PowerShell administration. Various cmdlets recognize different parameters that specify objects, names or other values. PowerShell is logical, powerful and flexible, enabling plenty of administrative options for managing services, such as storage.
Consider the sample cmdlet Get-Disk -FriendlyName "DataDisk". Here, the verb is Get, the noun is Disk and the parameter is -FriendlyName "DataDisk".
Gather storage information with PowerShell
Your first administrative task will be displaying information about existing storage. You could examine files and directories or individual disks, partitions or volumes. Regardless, start by reviewing the current storage configuration.
Displaying information with PowerShell almost always involves using the Get verb. Attach this verb to the various storage nouns to display the relevant information.
Use the following cmdlets to display this information:
- Get-Disk displays disk information, including disk number, friendly name, total size, health status and bus type. This cmdlet is essential for identifying the disk.
- Get-Partition displays information about the disk's physical partitions, partition numbers and sizes. It shows greater detail at the physical level than Get-Volume.
- Get-Volume displays volume information, including logical volumes, drive letters, file systems and available space. It provides greater detail at the logical level than Get-Partition.
- Get-PSDrive displays information on drive shares mapped on the system.
- Get-PhysicalDisk displays physical storage devices attached to the system, including hard disk and solid-state drives.
- Get-VirtualDisk displays information about virtual disks across all storage pools, including name, size and status.
Begin by establishing what kind of information you need. For example, if you need data on physical disk structures, focus on Get-Partition and Get-Disk. If you need logical volume information, use Get-Volume.

Display or test for files and directories
What if you need to gather information on the data stored on a device rather than about the device itself? Several cmdlets display directory and file information.
One of the most useful cmdlets for checking drive content is Test-Path. This cmdlet confirms whether all parts of a given path are true, letting you know whether particular directories or files exist. This information could be relevant when creating scripts because you might want to test for data before removing a partition or back up data before changing drive configurations. Test-Path returns $true if the given path exists or $false if not. Use these results to direct your script to take different actions depending on whether specific files exist.
Consider the example Test-Path -Path "C:\projects\2025projects\projectfile.docx. This cmdlet confirms all objects along the path, including the subdirectories and file. Use wildcards to broaden the match criteria.
The Get-ChildItem cmdlet is a more comprehensive way to display directories and files. Without a -Path parameter, it will show the current folder's contents. Add -Path C: projects to show the contents of the specified folder. Add the -Recurse option to drill down into child folders. This gives you Get-ChildItem -Path "C:\projects" -Recurse.

This is a handy way of discovering what information is stored in a particular location before you destroy data with a repartition or reformat cmdlet.
Manage new storage space
Your investigation of the system's storage could reveal unused and available storage space on existing disks. You can create partitions or volumes in this space and then format them with a file system, probably NTFS.
After you physically install the disk in the system, use the Get-Disk cmdlet to identify the <DiskNumber> value. This identifier lets you work with the specified disk using the other cmdlets.
Use the following steps to deploy your new storage:
- Initialize the disk. Use Initialize-Disk -Number <DiskNumber> -PartitionStyle GPT.
- Create a new disk partition. Use New-Partition -DiskNumber <DiskNumber> -UseMaximumSize -AssignDriveLetter.
- Format the partition. Use Format-Volume -DriveLetter <DriveLetter> -FileSystem NTFS -NewFileSystemLabel "Projects" -Confirm:$false.
- Confirm all drive settings. Use Get-Volume -DriveLetter <DriveLetter>.
Manually run these commands or automate them in a PowerShell script.
Manage storage space with a script
Use the above cmdlets to generate a PowerShell script using an editor such as Microsoft Visual Studio Code. Here is a sample script snippet to build from. It uses the $disk variable to identify the storage device.
# Identify the newly installed disk
$disk = Get-Disk | Where-Object PartitionStyle -eq 'RAW'
# Initialize the new disk
Initialize-Disk -InputObject $disk -PartitionStyle GPT
# Create a new disk partition using all available space and assign it the next available drive letter
$partition = New-Partition -DiskNumber $disk.Number -UseMaximumSize -AssignDriveLetter
# Format the new volume with the NTFS filesystem and label it Projects
Format-Volume -DriveLetter $partition.DriveLetter -FileSystem NTFS -NewFileSystemLabel "Projects" -Confirm:$false
Consider adding the following redirect instructions when you run the script command (assume the script is named new_disk.ps1):
.\new_disk.ps1 > new-disk.log *>&1
This option redirects standard output and error streams into the specified new-disk.log log file, which is helpful for troubleshooting.
Remove old storage space
Perhaps your investigation of the system's storage space revealed data, partitions or volumes that are no longer necessary. Removing these resources using PowerShell is as straightforward as adding them.
With the various storage nouns -- disk, partition, volume, etc. -- you'll use the standard deletion verbs, primarily Remove and Clear.
Here are a few sample cmdlets for removing storage resources:
- To delete the partition, making any stored data unavailable, use Remove-Partition -DiskNumber <DiskNumber> -PartitionNumber <PartitionNumber>.
- To remove volumes as identified by drive letter, use Remove-Volume -DriveLetter <DriveLetter>.
- To remove all partition information and uninitialize the disk, use Clear-Disk -Number <DiskNumber> -RemoveData.
Be very careful to back up all data before using these cmdlets to remove disk settings. Recovering lost data after running these cmdlets will be difficult or impossible. Also, think carefully before scripting disk deletions. It can be very easy to accidentally delete data as an automated process removes the storage space.
Conclusion
Managing Windows Server storage space is a common administrator task, and PowerShell makes that job easier. Running manual commands in the PowerShell console is usually faster than browsing through graphical wizard interfaces, but the true benefit of CLI environments is scripting.
Use the cmdlets in this article to investigate, create and remove storage configurations. Write PowerShell scripts to automate these processes, especially the investigation and creation tasks.
Check your standard processes today to see whether scripting storage space management with PowerShell could improve your workflows.
Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to Informa TechTarget, The New Stack and CompTIA Blogs.