简体   繁体   中英

Powershell Mount Point Automation: Drive letter appears after reboot

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM