Disk management with PowerShell: initialize, partition, format

Windows offers a historically grown collection of tools for disk management, both for the graphical user interface and the command line (diskpart, chkdsk, defrag, format.....)

But as you hopefully know, PowerShell is state of the art...
So here is the way to manage hard disks with PowerShell.

# Select disk
$disk = get-disk | Where partitionstyle -eq ‘raw’ | Out-GridView -PassThru
# Initialize Disk
$disk | Initialize-Disk -PartitionStyle GPT -PassThru
# Create & Format Partition
$disk | New-Partition -DriveLetter E -UseMaximumSize | Format-Volume -FileSystem NTFS

Reference:

https://devblogs.microsoft.com/scripting/use-powershell-to-initialize-raw-disks-and-to-partition-and-format-volumes/

https://www.windowspro.de/script/disk-management-powershell-initialisieren-partitionieren-formatieren