1

背景:

我正在开发一个 powershell 脚本,以通过 WinPE 从 USB 记忆棒自动安装。由于目标系统有多个驱动器,每个驱动器都可能有几个分区,Windows 很快就会用完驱动器号。我的部分脚本取消分配所有驱动器号,然后仅重新分配必要的磁盘。现在,我将硬编码的字母分配给某些分区,但我遇到了一个问题,其中一个字母没有被取消分配。

问题是我不知何故有一个带有分配驱动器号的卷,但显然没有底层分区,并且由于Remove-PartitionAccessPath需要一个分区对象,因此无法从 powershell 执行此操作(不诉诸diskpart)。

这是输出diskpart- 您可以看到所选磁盘没有分区,但不知何故有一个卷:

Microsoft DiskPart version 10.0.15063.0

Copyright (C) Microsoft Corporation.
On computer: MININT-6GI0UNM

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online         5589 GB      0 B        *
  Disk 1    Online         5589 GB      0 B        *
  Disk 2    Online         5589 GB      0 B        *
  Disk 3    Online         5589 GB      0 B        *
  Disk 4    Online         5589 GB      0 B        *
  Disk 5    Online         5589 GB      0 B        *
  Disk 6    Online         5589 GB      0 B        *
  Disk 7    Online         5589 GB      0 B        *
  Disk 8    Online         5589 GB      0 B        *
  Disk 9    Online         5589 GB      0 B        *
  Disk 10   Online         5589 GB      0 B        *
  Disk 11   Online         5589 GB      0 B        *
  Disk 12   Online          447 GB      0 B        *
  Disk 13   Online          447 GB      0 B        *
  Disk 14   Online          232 GB      0 B        *
  Disk 15   Online           29 GB    29 GB
  Disk 16   Online           28 GB      0 B        *

DISKPART> sel disk 15

Disk 15 is now the selected disk.

DISKPART> list part

There are no partitions on this disk to show.

DISKPART> detail disk

ATA Hypervisor USB Device
Disk ID: E0623CE6
Type   : USB
Status : Online
Path   : 0
Target : 0
LUN ID : 0
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only  : No
Boot Disk  : No
Pagefile Disk  : No
Hibernation File Disk  : No
Crashdump Disk  : No
Clustered Disk  : No

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 20    E                       Removable       0 B  Unusable

DISKPART>

当我尝试从 powershell 中删除该字母时,会发生以下情况:

PS X:\sources> Get-Volume -DriveLetter E | Remove-PartitionAccessPath -AccessPath "E:"
Remove-PartitionAccessPath : The input object cannot be bound to any parameters for the command either because the
command does not take pipeline input or the input and its properties do not match any of the parameters that take
pipeline input.
At line:1 char:29
+ ... t-Volume -DriveLetter E | Remove-PartitionAccessPath -AccessPath "E:"
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_Volume (Ob...rosoft/Wind...):PSObject) [Remove-PartitionAccessPat
   h], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Remove-PartitionAccessPath

PS X:\sources> Get-Volume -DriveLetter E | fl *


OperationalStatus     : Unknown
HealthStatus          : Healthy
DriveType             : Removable
FileSystemType        : Unknown
DedupMode             : NotAvailable
ObjectId              : {1}\\MININT-6GI0UNM\root/Microsoft/Windows/Storage/Providers_v2\WSP_Volume.ObjectId="{63585070-
                        3cd2-11e7-b877-806e6f6e6963}:VO:\\?\Volume{635850c4-3cd2-11e7-b877-806e6f6e6963}\"
PassThroughClass      :
PassThroughIds        :
PassThroughNamespace  :
PassThroughServer     :
UniqueId              : \\?\Volume{635850c4-3cd2-11e7-b877-806e6f6e6963}\
AllocationUnitSize    : 0
DriveLetter           : E
FileSystem            :
FileSystemLabel       :
Path                  : \\?\Volume{635850c4-3cd2-11e7-b877-806e6f6e6963}\
Size                  : 0
SizeRemaining         : 0
PSComputerName        :
CimClass              : ROOT/Microsoft/Windows/Storage:MSFT_Volume
CimInstanceProperties : {ObjectId, PassThroughClass, PassThroughIds, PassThroughNamespace...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties



PS X:\sources> Get-Volume -DriveLetter E | Get-Partition
PS X:\sources> $null -eq (Get-Volume -DriveLetter E | Get-Partition)
True

Powershell版本表:

PS X:\sources> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.15063.0
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.0
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

如有必要,我可以尝试获取有关磁盘内容的更多详细信息。

这可能是什么原因造成的?有powershell解决方法吗?

注意:我意识到让 Windows 选择驱动器号而不是硬编码它们可能会更好,但我仍然对神秘的卷感到好奇。

4

1 回答 1

-1

尝试这个:

Get-Volume -Drive 'E' | Get-Partition | Remove-PartitionAccessPath -AccessPath 'E:\'

参考:https ://blogs.technet.microsoft.com/heyscriptingguy/2015/12/07/powertip-use-powershell-to-remove-drive-letter/

于 2017-05-24T05:36:08.483 回答