gpt4 book ai didi

PowerShell 和磁盘部分

转载 作者:行者123 更新时间:2023-12-04 23:09:50 26 4
gpt4 key购买 nike

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

我正在尝试在 powershell 中编写一个脚本,该脚本将能够根据几个唯一字段识别卷。问题在于我在用powershell解释diskpart的“list volume”命令的输出时遇到了困难。

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

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 on the class Win32_Volume 上的帖子.

我希望这可以帮助其他人谢谢大家的帮助!

关于PowerShell 和磁盘部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3230277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com