Add disk via PowerShell

To add a disk to a Windows server with PowerShell I find these comments useful:

# Create a remote command line connection to the server
Enter-PSSession -Computername <computer> -Credential <domain\username>

# Retrieve disk information
Get-Disk | Sort-Object Number

#?Initialize new disk
Initialize-Disk -Number 1

#?Change emtpy CD-ROM driveletter from D to A
$drive = gwmi win32_volume -Filter “DriveLetter = ‘D:'”
$drive.DriveLetter = “A:”

#?Create a partition on the new disk
New-Partition -DiskNumber 1 -UseMaximumSize -AssignDriveLetter

# Check if the new partition has been created
Get-disk -Number 1 | get-partition

# Format new volume
Format-Volume -DriveLetter D -FileSystem NTFS

# Change the drive label
Set-Volume -DriveLetter D -NewFileSystemLabel “DATA”

#?Retrieve volumes sorted by driveletter
Get-Volume | Sort-Object Driveletter