Powershell - Managing disks, partitions and volumes
To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!
Hello, A new article on how to manage disks, partitions and volumes in Powershell.
# List the commands for managing disksGet-Command -Module Storage
## Disk# List disksGet-Disk
# List data disksGet-Disk | Where-Object IsSystem -Eq $False
# List offline disksGet-Disk | Where-Object IsOffline -Eq $True
# List USB-connected disksGet-Disk | Where-Object -Property BusType -eq USB
# List bootable disksGet-Disk | Where-Object -Property IsBoot -eq $true
# Display the serial number, model and firmware version of the disksGet-Disk | Select-Object -Property FriendlyName,SerialNumber,Model,FirmwareVersion
# Bring all offline disks onlineGet-Disk | Where-Object IsOffline -Eq $True | Set-Disk -IsOffline $False
# Initialise uninitialised disks in GPTGet-Disk | where-object PartitionStyle -eq 'raw' | Initialize-Disk -PartitionStyle GPT
##Partition# List the partitions on a diskGet-Partition -DiskNumber 0
# List all partitionsGet-Disk | Get-Partition | Select-Object -Property *
# Display partition information by drive letterGet-Partition -DriveLetter C
# Display partition information by partition numberGet-Partition -PartitionNumber 4
## Partition# Create a new 30 GB partition with an automatically defined drive letterNew-Partition -DiskNumber 1 -Size 30GB -AssignDriveLetter
# Create a new partition with drive letter G using all remaining disk spaceNew-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter G
# Remove partitions from a diskGet-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 FResize-Partition -DriveLetter F -Size $SupportedSize.SizeMax
# Change the size of a partition to a defined sizeResize-Partition -DriveLetter F -Size 25GB
# Change the letter of a partitionSet-Partition -DriveLetter F -NewDriveLetter H
# Remove a specific partition without requesting confirmationRemove-Partition -DiskNumber 1 -PartitionNumber 1 -Confirm:$false
# Delete all the partitions on a disk without prompting for confirmationClear-Disk -Number 1 -Confirm:$False
# Delete data and OEM partitions without prompting for confirmationClear-Disk -FriendlyName usbkey -RemoveData -RemoveOEM -Confirm:$False
## Volume# Format the volume in NTFS (or FAT, FAT32, exFat, ReFS) and give it a name without asking for confirmationFormat-Volume -DriveLetter F -FileSystem NTFS -NewFileSystemLabel 'Data' -Confirm:$false
# List all volumesGet-Volume
# Display a specific volume using its drive letterGet-Volume -DriveLetter c
# List volumes that require maintenanceget-volume | Where-Object -Property HealthStatus -NE healthy
# List removable volumesget-volume | Where-Object -Property DriveType -EQ Removable
# Display disk space informationGet-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)}}# orGet-Volume | Select-Object -Property DriveLetter,FriendlyName,size,sizeremaining
# Display the number of NTFS file system errors on a volumeGet-VolumeCorruptionCount -DriveLetter D
# Initialise, partition and formatGet-Disk | 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 keyClear-Disk -FriendlyName 'usbkey' -RemoveData -RemoveOEM -Confirm:$False -PassThru | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel 'USBDATA'
Related links
Powershell - Testing network connectivity and port accessibility
Testing network connectivity and port accessibility with PowershellPowershell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)Powershell - Testing name resolution (equivalent to nslookup)
Powershell commands to test name resolution (equivalent to nslookup)Powershell - View and manage DNS configuration of network interfaces
Powershell commands to display and manage DNS configuration of network interfacesPowershell - Managing IP configuration of network interfaces
Powershell commands to view and modify the IP configuration of network interfacesPowershell - Managing the status and configuration of network interfaces
Powershell commands to view and modify the status and configuration of network interfaces (disable IPv6, enable/disable an interface)
Follow me on
Support me
Last content
Powershell - Testing network connectivity and port accessibility
Powershell - Display network connections (equivalent to netstat)
Powershell - Testing name resolution (equivalent to nslookup)
Powershell - View and manage DNS configuration of network interfaces
Powershell - Managing IP configuration of network interfaces
Powershell - Managing the status and configuration of network interfaces
Powershell and the Left Hand Side
Powershell - Managing disks, partitions and volumes