Powershell assign a drive and mount point

14 May,2019 by Jack Vamvas

Question: What are the powershell commands to create to ASSIGN a drive letter and then create a MOUNT POINT?

Answer: These powershell command  examples   will  assign a drive letter and then  create a mount point. You'll need to first know the Disk ID and also decide on the drive letter you need to assign 

If you want to create a mount point , then  use the MOUNT POINT section  

If the intention is to automate the assigning of drive letters to new partitions , and also dynamically identify the diskid than you'll need to  wrap some extra code around these steps to identify the diskid and also other parameter values, e.g Filesystem or AllocationUnitSize or PartitionStyle

Some useful Powershell commands to assist in assigning a drive or create a mount point using Powershell.

Get-Disk  - (Gets one or more disks visible to the operating system.From the MS documentation:"The Get-Disk cmdlet gets one or more Disk objects visible to the operating system, or optionally a filtered list")

Get-Disk -Number 3  - (Get the disk by disk number.In this example - the disk is number 3.)


=======ASSIGN DRIVE==========
$letterassign = "H"
$diskid = "4"
Get-Disk –Number $diskid | Initialize-Disk –PartitionStyle GPT
New-Partition -DiskNumber $diskid -Driveletter $letterassign -UseMaximumSize
Format-Volume -DriveLetter $letterassign -FileSystem NTFS -AllocationUnitSize 65536 –Confirm:$false


For the MOUNTPOINT option - you will need to first create the folder on the root disk. In the example below we're creating a mount point and it's access path is F:\mytest. That folder must already exist !  Then it becomes the access path to the new disk set up 


======MOUNT POINT=============
$diskid = "4"
Set-Disk -Number $diskid -IsReadOnly $false
Get-Disk –Number $diskid | Initialize-Disk –PartitionStyle GPT
New-Partition –DiskNumber $diskid –UseMaximumSize
Add-PartitionAccessPath -DiskNumber $diskid -PartitionNumber 2 –AccessPath "F:\mytest"
Get-Partition –Disknumber $diskid –PartitionNumber 2 | Format-Volume –FileSystem NTFS –NewFileSystemLabel MPData -AllocationUnitSize 65536 –Confirm:$false





Author: Jack Vamvas (http://www.sqlserver-dba.com)


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on Powershell assign a drive and mount point

sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer