How do I make new disks (make them online, initialize them, add new partition)?

Using the GUI in Windows server, I can add a new partition once new disks are physically added. Here is how the process goes without PowerShell:

  1. physically add a new disk to the server
  2. turn the server on and log in
  3. Go to Server Manager -> Computer Management -> Storage -> Disk Management.
  4. Right click “Disk 1” go to Online
  5. Right click “Disk 1” go to Initialize Disk
  6. Right click “Disk 1” go to New Simple partition …
    I create the disk to have it appear as the F drive utilizing all possible space.

I want to do steps 3 through 6 in PowerShell. How do I do this?

As long as you’re using at least Server 2012, something like this should work:

Set-Disk -Number 1 -IsOffline $false -IsReadOnly $false
Initialize-Disk -Number 1 -PartitionStyle GPT
New-Partition -DiskNumber 1 -DriveLetter F -UseMaximumSize
Format-Volume -DriveLetter F -FileSystem NTFS

That particular example is hard-coded to use disk number 1; instead, you might want to do something with Get-Disk, and filter for disks that are currently offline.

For older operating systems, you’ll probably wind up using diskpart.exe.