Set PhysicalDisk - PowerShell


Overview

Set-PhysicalDisk configures various settings and properties for physical disk drives in a Windows environment. It allows administrators to modify attributes such as disk layout, drive letter assignment, and partition alignment.

Syntax

Set-PhysicalDisk [-Number] <UInt32> [-IsBootDisk] <Boolean> [-IsReadOnly]
<Boolean> [-AlignmentOffset] <UInt64> [-FileSystem] <String> [-Gpt]
[-VolumeLabel] <String> [-WarningAction] <String> [-Confirm] <Boolean>
[-WhatIf] <Boolean> [<CommonParameters>]

Options/Flags

  • -Number: Specifies the physical disk number.
  • -IsBootDisk: Configures the disk as a boot disk.
  • -IsReadOnly: Sets the disk to read-only mode.
  • -AlignmentOffset: Aligns partitions to the specified offset in bytes.
  • -FileSystem: Formats the disk with the specified file system.
  • -Gpt: Creates a GUID partition table (GPT) on the disk.
  • -VolumeLabel: Assigns a volume label to the disk.
  • -WarningAction: Specifies the action to take when warnings are encountered.
  • -Confirm: Prompts for confirmation before executing the command.
  • -WhatIf: Displays what the command would do without executing it.

Examples

Assigning a Drive Letter:

Set-PhysicalDisk -Number 0 -IsBootDisk $true -FileSystem NTFS -VolumeLabel "System"

Creating a GPT Disk:

Set-PhysicalDisk -Number 1 -Gpt -FileSystem exFAT -VolumeLabel "Data"

Aligning Partitions:

Set-PhysicalDisk -Number 2 -AlignmentOffset 1048576

Common Issues

Disk Not Found:

If the specified physical disk number does not exist, the command will fail. Check the disk number using Get-PhysicalDisk.

Insufficient Access:

You may need administrative privileges to modify physical disk settings. Use Start-Process with -Verb RunAs to elevate the command.

Integration

This command can be integrated into scripts or combined with other commands, such as Format-Volume, to automate disk management tasks. For example:

Get-PhysicalDisk | Set-PhysicalDisk -IsBootDisk $true -FileSystem NTFS | Format-Volume -FileSystemLabel "System"
  • Get-PhysicalDisk
  • New-Partition
  • Remove-Partition