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

 

=======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

======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)


Share:

Verify your Comment

Previewing your Comment

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

Working...
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.

Working...

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