Set Partition - PowerShell


Overview

The Set-Partition cmdlet modifies properties of a partition on a physical disk. This enables you to manage disk partitions, configure their sizes, file systems, and other attributes. It’s particularly useful for disk partitioning, storage management, and system administration tasks.

Syntax

Set-Partition [-PartitionNumber] <Int32> -FileSystem <String> [-Size <Int32>] [-NewPartitionNumber <Int32>] [-Label <String>] [-Boot] [-Convert] [-Unrecoverable] [-Force] [-Confirm] [-WhatIf] [-PassThru] [<CommonParameters>]

Options/Flags

  • -FileSystem: Specifies the file system to format the partition with.
  • -Size: Sets the size of the partition in megabytes (MB).
  • -NewPartitionNumber: Assigns a new partition number to the partition.
  • -Label: Sets the volume label for the partition.
  • -Boot: Marks the partition as bootable.
  • -Convert: Converts the partition to the specified file system.
  • -Unrecoverable: Prevents the partition from being recovered by data recovery tools.
  • -Force: Suppresses confirmation prompts and forces the operation.
  • -Confirm: Prompts for confirmation before executing the operation.
  • -WhatIf: Simulates the operation without making any changes.
  • -PassThru: Returns an object representing the modified partition.

Examples

Example 1: Format a partition as NTFS

Set-Partition -PartitionNumber 1 -FileSystem NTFS

Example 2: Resize a partition and assign a label

Set-Partition -PartitionNumber 2 -Size 500 -Label "Data"

Example 3: Convert a partition to FAT32

Set-Partition -PartitionNumber 3 -Convert FAT32

Common Issues

  • Insufficient disk space: Ensure there’s enough free space on the disk to complete the operation.
  • Partition table corruption: Partition table corruption can cause errors. Use Repair-Partition to fix it.
  • File system errors: Check the file system for errors before formatting the partition.

Integration

  • Combine with Get-Partition to retrieve partition information before modifying it.
  • Use Initialize-Disk to prepare a new disk for partitioning.
  • Integrate with New-Partition and Remove-Partition for comprehensive disk management.
  • Get-Partition
  • Initialize-Disk
  • Repair-Partition