简体   繁体   English

Powershell Mount Point Automation:重启后会显示驱动器号

[英]Powershell Mount Point Automation: Drive letter appears after reboot

I've got a strange behavior with powershell created moint points: 我有一个奇怪的行为,PowerShell创建了moint点:

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. 起初我将挂载点磁盘创建为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. 重启后,磁盘管理MMC中也未显示挂载点。 Using NTFS fixed the last issue, but the drive letter stil reappears when using the above script. 使用NTFS修复了上一个问题,但在使用上述脚本时,驱动器号stil重新出现。

If I delete the driver letter by hand it doesn't come back. 如果我手动删除了驱动器号,它就不会回来。

The system is a Server 2012 R2 该系统是Server 2012 R2

Any ideas? 有任何想法吗?

After the tip from Harry Johnston I found a working solution: 在Harry Johnston的小费之后,我找到了一个有效的解决方案:

  $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. 最后一行已添加,并阻止操作系统自动添加驱动器号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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