Reputation: 76
I've got a strange behavior with powershell created moint points:
My script creates partitions and mounts them into the file system. After a reboot every partition has a drive letter added.
My script so far:
$disks = Get-Disk|where {$_.Number -ge 5} ## >= 5: index disks
$counter = 1
foreach( $disk in $disks){
$diskName="Disk_"+$counter.ToString("00")
$disk = $disk | initialize-Disk -PartitionStyle GPT -passthru|new-partition -UseMaximumSize
Format-Volume -Partition $disk -FileSystem ReFS -NewFileSystemLabel $diskName -Confirm:$false
New-Item -ItemType Directory -Path ( "f:\Mounts\"+$diskName )
$disk | Add-PartitionAccessPath -AccessPath ( "f:\Mounts\"+$diskName )
}
At first I created the mount point disk as ReFS. This worked well, but the drive letter also appeared after a reboot. Also the mount point wasn't shown in the disk management MMC after the reboot. Using NTFS fixed the last issue, but the drive letter stil reappears when using the above script.
If I delete the driver letter by hand it doesn't come back.
The system is a Server 2012 R2
Any ideas?
Upvotes: 1
Views: 2208
Reputation: 76
After the tip from Harry Johnston I found a working solution:
$disks = Get-Disk|where {$_.Number -ge 5} ## >= 5: index disks
$counter = 1
foreach( $disk in $disks){
$diskName="Disk_"+$counter.ToString("00")
$disk = $disk | initialize-Disk -PartitionStyle GPT -passthru|new-partition -UseMaximumSize
Format-Volume -Partition $disk -FileSystem ReFS -NewFileSystemLabel $diskName -Confirm:$false
New-Item -ItemType Directory -Path ( "f:\Mounts\"+$diskName )
$disk | Add-PartitionAccessPath -AccessPath ( "f:\Mounts\"+$diskName )
$disk | Set-Partition -NoDefaultDriveLetter $true
}
The last line was added and prevents the operating system in adding a drive letter automatically.
Upvotes: 1