powershell和diskpart

Maa*_*tin 4 powershell

总之,我有一个卷,我需要分配一个驱动器号(使用diskpart).现在的问题在于音量不会保持不变.您输入磁盘部分a执行"列表卷",特定卷将是卷0,然后"退出".再次输入并再次执行"列表卷",这次是第4卷.所以它继续.现在,如果这是由一个人完成的,那么这不是一个问题,但是这是一个自动化任务,它将"断开"Windows 2003上的卷并在其他服务器上使用并再次安装在Windows 2003服务器上.

我正在尝试在powershell中编写一个脚本,该脚本能够根据一些独特的字段识别卷.问题在于我用PowerShell解释了diskpart的"list volume"命令的输出.

以下命令提供了我需要使用的输出,但是在我丢失之后.

cls
$dp = "list volume" | diskpart | ? { $_ -match "^  [^-]" }
$dp | format-table  -auto
Run Code Online (Sandbox Code Playgroud)

这是它提供的输出,我正在寻找的音量是第1卷.

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  Volume 0     F                       DVD-ROM         0 B  Healthy            
  *Volume 1                             Partition    100 GB  Healthy*            
  Volume 2     E   DATA         NTFS   Partition    547 GB  Healthy            
  Volume 3     C   OS           NTFS   Partition     39 GB  Healthy    System  
  Volume 4     D   APPS         NTFS   Partition     98 GB  Healthy            
Run Code Online (Sandbox Code Playgroud)

请允许任何人帮我正确的方向.我正处于我的束缚之中.

Maa*_*tin 6

是的,我知道了!!

这是答案.
使用VB脚本我设法创建了一个完成我正在寻找的脚本,然后我转换为Powershell,下面是脚本.

$drive = gwmi Win32_Volume | where {$_.DeviceID -like "*b0f012f6-82b1-11df-a41c-001f29e8f0be*"}
$drive.AddMountPoint("T:\")
$drive.DriveLetter = "T:"
$drive.Put_
$drive.Mount()
Run Code Online (Sandbox Code Playgroud)

我通过运行以下脚本获得的设备ID:

# get volumes on this system
$volumes = get-wmiobject Win32_Volume
# display volume info
# There are {0} volumes on this system, as follows: " -f ($volumes.length)
# Iterate through volumes and display information
foreach ($vol in $volumes) {
    "Volume: {0}" -f ++$i
    "============================="
    $vol | Format-List Access,Automount,Availability,BlockSize,BootVolume,Capacity,Caption,Compressed,ConfigManagerErrorCode,ConfigManagerUserConfig,CreationClassName,Description,DeviceID,DirtyBitSet,DriveLetter,DriveType,ErrorCleared,ErrorDescription,ErrorMethodology,FileSystem,FreeSpace,IndexingEnabled,InstallDate,Label,LastErrorCode,MaximumFileNameLength,Name,NumberOfBlocks,PageFilePresent,PNPDeviceID,PowerManagementCapabilities,PowerManagementSupported,Purpose,QuotasEnabled,QuotasIncomplete,QuotasRebuilding,SerialNumber,Status,StatusInfo,SupportsDiskQuotas,SupportsFileBasedCompression,SystemCreationClassName,SystemName,SystemVolume
}
Run Code Online (Sandbox Code Playgroud)

来自Win32_Volume类的msdn上的帖子.

我希望这可以帮助别人

感谢所有帮助的人!