# List the commands for managing disks
Get-Command -Module Storage
Where-Object IsSystem -Eq $False
Where-Object IsOffline -Eq $True
# List USB-connected disks
Where-Object -Property BusType -eq USB
Where-Object -Property IsBoot -eq $true
# Display the serial number, model and firmware version of the disks
Get-Disk | Select-Object -Property FriendlyName,SerialNumber,Model,FirmwareVersion
# Bring all offline disks online
Where-Object IsOffline -Eq $True |
Set-Disk -IsOffline $False
# Initialise uninitialised disks in GPT
where-object PartitionStyle -eq 'raw' |
Initialize-Disk -PartitionStyle GPT
# List the partitions on a disk
Get-Partition -DiskNumber 0
Select-Object -Property *
# Display partition information by drive letter
Get-Partition -DriveLetter C
# Display partition information by partition number
Get-Partition -PartitionNumber 4
# Create a new 30 GB partition with an automatically defined drive letter
New-Partition -DiskNumber 1 -Size 30GB -AssignDriveLetter
# Create a new partition with drive letter G using all remaining disk space
New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter G
# Remove partitions from a disk
Get-Partition -DiskNumber 1 |
Remove-Partition -Confirm:$false
# Modify the size of a partition (cannot be less than the disk space used and greater than the size of the disk)
$SupportedSize = Get-PartitionSupportedSize -DriveLetter F
Resize-Partition -DriveLetter F -Size $SupportedSize.SizeMax
# Change the size of a partition to a defined size
Resize-Partition -DriveLetter F -Size 25GB
# Change the letter of a partition
Set-Partition -DriveLetter F -NewDriveLetter H
# Remove a specific partition without requesting confirmation
Remove-Partition -DiskNumber 1 -PartitionNumber 1 -Confirm:$false
# Delete all the partitions on a disk without prompting for confirmation
Clear-Disk -Number 1 -Confirm:$False
# Delete data and OEM partitions without prompting for confirmation
Clear-Disk -FriendlyName usbkey -RemoveData -RemoveOEM -Confirm:$False
# Format the volume in NTFS (or FAT, FAT32, exFat, ReFS) and give it a name without asking for confirmation
Format-Volume -DriveLetter F -FileSystem NTFS -NewFileSystemLabel 'Data' -Confirm:$false
# Display a specific volume using its drive letter
Get-Volume -DriveLetter c
# List volumes that require maintenance
Where-Object -Property HealthStatus -NE healthy
Where-Object -Property DriveType -EQ Removable
# Display disk space information
Get-CimInstance Win32_LogicalDisk |
select-object DeviceId, VolumeName,
@{n='TotalSize (GB)';e={[math]::Round($_.Size/1GB,2)}},
@{n='UsedSpace (GB)';e={[math]::Round($_.Size/1GB - $_.FreeSpace/1GB,2)}},
@{n='FreeSpace (GB)';e={[math]::Round($_.FreeSpace/1GB,2)}}
Select-Object -Property DriveLetter,FriendlyName,size,sizeremaining
# Display the number of NTFS file system errors on a volume
Get-VolumeCorruptionCount -DriveLetter D
# Initialise, partition and format
Where-Object PartitionStyle -eq 'raw' |
Initialize-Disk -PartitionStyle GPT -PassThru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem NTFS -NewFileSystemLabel 'Data'
# Clean and reformat a USB key
Clear-Disk -FriendlyName 'usbkey' -RemoveData -RemoveOEM -Confirm:$False -PassThru |
Initialize-Disk -PartitionStyle MBR -PassThru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem NTFS -NewFileSystemLabel 'USBDATA'