PowerShell – Format SQL Disk Partition

When installing SQL Server you have to ensure that the DATA, LOG and TEMPDB disk are formatted with 64K block size (allocation unit size). This must be done to reduce number of physical page reads from disk when SQL Server engine needs fresh data that is not updated in cache. Since database files most certain are larger than 64K, this is the block size you need for your database files.

As a result, I have implemented an unattended installation script in PowerShell where I check the Block size of the DATA, LOG and TEMP disks. If they don’t have 64K block size, I will format them immediatly.

Here is my PowerShell function for this use.

function FormatSQLDisk([string]$driveletter, [string]$drivelabel)
{
    Format-Volume 	`
	-DriveLetter $driveletter `
	-NewFileSystemLabel $drivelabel `
        -FileSystem NTFS `
	-AllocationUnitSize 65536 –Force -Confirm:$false
}

Happy formatting…