Checks an NTFS drive for the SQL Server-recommended 64 KB (65536 byte) allocation unit size. If the cluster size differs, the function backs up all data with robocopy, formats the volume, restores the data, and cleans up the backup — all in one auditable workflow. Returns AlreadyOK without making changes if the drive is already correctly formatted.
Execution Flow
Synopsis
Drive C: is permanently prohibited — a hard-coded guard prevents accidental formatting. BackupPath must reside on C:. The cluster size is read first via fsutil fsinfo ntfsinfo (with fallback to Get-Volume.AllocationUnitSize). If the drive is already at 65536 bytes, the function returns AlreadyOK without any changes. The in-use check scans Get-Process module file paths and returns InUse if any process has open file handles on the drive. robocopy uses flags /E /COPYALL /R:3 /W:5 /NP /LOG+; exit codes 0–3 are treated as success.
No dbatools required. Requires local administrator rights. Robocopy is a standard Windows component. -WhatIf returns Status=WhatIf without touching any data.
All data on the drive is destroyed during formatting. The robocopy backup mitigates this risk, but if the restore fails the backup remains under -BackupPath on C: for manual recovery. Never run against a drive actively used by a running SQL Server instance.
Syntax
Invoke-sqmFormatDrive64K-DriveLetter <String> # required; single letter A-Z (not C)
[-BackupPath <String>] # default: C:\System\DriveBackup (must be on C:)
[-Force] # skip confirmation prompt
[-WhatIf] [-Confirm]
Parameters
Parameter
Type
Default
Description
-DriveLetter
String
—
Required. Single drive letter A–Z. C is explicitly prohibited (ValidatePattern enforced).
-BackupPath
String
C:\System\DriveBackup
Temporary backup path on C: for data before formatting. Must start with C:\.
-Force
Switch
$false
Skip the interactive confirmation prompt before formatting.
Return Value
Property
Description
DriveLetter
Target drive letter.
Label
Drive label (preserved through format).
PreviousClusterSize
Allocation unit size in bytes before the operation.
NewClusterSize
Allocation unit size in bytes after the operation (65536 on success).
DataBackedUp
$true if robocopy backup completed successfully.
BackupFolder
Path of the backup folder on C: ($null if no data was present).
DataRestored
$true if robocopy restore completed successfully.
BackupCleanedUp
$true if the backup on C: was deleted after successful restore.
Status
AlreadyOK — no changes; Formatted — success; InUse — drive in use; Error — any failure; WhatIf — dry run.
Message
Human-readable result with reboot/restore warnings where applicable.
Examples
# Check drive D: and format if needed (with confirmation prompt)Invoke-sqmFormatDrive64K-DriveLetter'D'# Dry run — shows what would happen, no data changedInvoke-sqmFormatDrive64K-DriveLetter'E'-WhatIf# Format without confirmation, custom backup pathInvoke-sqmFormatDrive64K-DriveLetter'F' `
-BackupPath'C:\Temp\DriveBackup'-Force# Check result$r = Invoke-sqmFormatDrive64K-DriveLetter'D'-ForceWrite-Host"$($r.Status): $($r.PreviousClusterSize) → $($r.NewClusterSize) bytes | Restored: $($r.DataRestored)"