powershell 和 diskpart

2024-03-01

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

我正在尝试在 powershell 中编写一个脚本,该脚本将能够根据一些唯一的字段来识别卷。问题在于我陷入了用 powershell 解释 diskpart 的“列表卷”命令的输出上。

以下命令提供了我需要使用的输出,但在我迷路之后。

cls
$dp = "list volume" | diskpart | ? { $_ -match "^  [^-]" }
$dp | format-table  -auto

这是它提供的输出,我要查找的卷是卷 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            

任何人都可以帮助我朝正确的方向前进吗?我已经穷途末路了。


是的,我知道了!!

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

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

我通过运行以下脚本获得的设备 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
}

从一个帖子msdn 关于 Win32_Volume 类 http://msdn.microsoft.com/en-us/library/aa394515%28v=VS.85%29.aspx#4.

我希望这可以帮助别人

感谢所有提供帮助的人!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

powershell 和 diskpart 的相关文章

随机推荐