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…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s