Disks and Partitions Management with Windows PowerShell
In this article we will learn how to manage disk and create disk partition for new disk using the window feature PowerShell or command line by PowerShell.
Using the PowerShell we can perform or manage all the local disk and partition same like Window Disk Management ( GUI - diskmgmt.msc )
Create Partition on Disk Using PowerShell |
Who to Open PowerShell ?
To Open PowerShell, Go to Search and type PowerShell See the below screenshot
Window Search ==> Windows PowerShell ==> Run as Administrator
How to Create a Partition on Disk ?
Step 1 -
Print all the installed disk using PowerShell cmdline
PS C:/>Get-Disk
Step 2 -
Create Disk Partition
To create a new partition on a disk we can use the New-Partition cmdlet,
Example 1: We will create a 500 GB partition on disk 1 and assign the letter D: to it
PS C:\> New-Partition –DiskNumber 1 -Size 500gb -DriveLetter D
Example 2: We will create second partition to occupy all available disk space using UseMaximumSize attribute also will use -AssignDriveLetter to assign drive latter automatically
PS C:\> New-Partition –DiskNumber 1 -AssignDriveLetter –UseMaximumSize
Here, Auto Assign Drive Letter is E and size is 431GB, if we want to change the drive letter we can do using below command
You can change the assigned letter using this command:
PS C:\> Set-Partition –DriveLetter E -NewDriveLetter F
Formatting a partition with PowerShell
In the above example we have created 2 partition Let’s format new partition in the NTFS and set the DBData volume label:
PS C:\> Format-Volume -DriveLetter E -FileSystem NTFS -NewFileSystemLabel SiteData -Confirm:$false
- -DriveLetter E: specifies the drive letter of the partition to format.
- -FileSystem NTFS: specifies the file system to use, which is NTFS in this case.
- -NewFileSystemLabel SiteData: specifies the label for the new file system, which is SiteData in this case.
- -Confirm:$false: suppresses the confirmation prompt that usually appears before formatting.
Note: Be carefully using PowerShell and double check before doing anything