当 FriendlyName 相同时,使用 PowerShell Set-PhysicalDisk

当 FriendlyName 相同时,使用 PowerShell Set-PhysicalDisk

Get-PhysicalDisk在有 4 个硬盘的虚拟机中运行了该程序。结果是:

FriendlyName             SerialNumber CanPool OperationalStatus HealthStatus Usage         Size
------------             ------------ ------- ----------------- ------------ -----         ----
VMware, VMware Virtual S              False   OK                Healthy      Auto-Select  60 GB
VMware, VMware Virtual S              False   OK                Healthy      Auto-Select 100 GB
VMware, VMware Virtual S              False   OK                Healthy      Auto-Select 200 GB
VMware, VMware Virtual S              False   OK                Healthy      Auto-Select 400 GB

在上面的结果中我没有看到序列号或者任何其他唯一 ID。

现在,我需要运行Set-PhysicalDisk。网络上的所有示例都使用唯一的 FriendlyName 或类似的东西PhysicalDisk1。首先,有 4 个磁盘具有相同的 FriendlyName,所以我认为我不能使用它。其次,我认为PhysicalDisk{number}是一个通过索引指向磁盘的特殊名称,但它似乎不起作用。

Set-PhysicalDisk如果我想指定上面的第二个磁盘(大小= 100GB),我应该传递什么?

PS C:\Users\Administrator> Set-PhysicalDisk -FriendlyName "VMware, VMware Virtual S" -Usage Retired
Set-PhysicalDisk : Not Supported
At line:1 char:1
+ Set-PhysicalDisk -FriendlyName "VMware, VMware Virtual S" -Usage Reti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (StorageWMI:ROOT/Microsoft/..._StorageCmdlets) [Set-PhysicalDisk], CimException
    + FullyQualifiedErrorId : StorageWMI 1,Set-PhysicalDisk

PS C:\Users\Administrator> Set-PhysicalDisk PhysicalDisk1 -Usage Retired
Set-PhysicalDisk : The requested object could not be found.
At line:1 char:1
+ Set-PhysicalDisk PhysicalDisk1 -Usage Retired
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (PS_StorageCmdlets:ROOT/Microsoft/..._StorageCmdlets) [Set-PhysicalDisk], CimException

答案1

您可以Set-PhysicalDisk使用UniqueID

UniqueID要检索

Get-PhysicalDisk | Select-Object SerialNumber,UniqueID

根据进行更新UniqueID

Set-PhysicalDisk -UniqueId "{<insert_UniqueID>}"

答案2

您可以分配该磁盘“目的”到变量。使用该变量,您可以对变量本身执行操作 - 甚至不需要友好名称或者序列号

细节

就我而言 FriendlyName,也没有任何SerialNumber

FriendlyName   CanPool  OperationalStatus   HealthStatus  Usage             Size
------------   -------  -----------------   ------------  -----             ----
PhysicalDisk1  False    OK                  Healthy       Auto-Select    1.82 TB
PhysicalDisk3  False    OK                  Healthy       Auto-Select    1.82 TB
PhysicalDisk4  False    OK                  Healthy       Auto-Select    1.82 TB
PhysicalDisk0  False    OK                  Healthy       Auto-Select  111.79 GB
PhysicalDisk8  False    OK                  Healthy       Auto-Select    1.82 TB
PhysicalDisk2  False    OK                  Healthy       Auto-Select  465.76 GB
               False    Lost Communication  Warning       Retired      930.75 GB
PhysicalDisk6  False    OK                  Healthy       Auto-Select  930.75 GB
PhysicalDisk9  False    OK                  Healthy       Auto-Select  930.75 GB
PhysicalDisk7  False    OK                  Healthy       Auto-Select    1.82 TB
PhysicalDisk5  False    OK                  Healthy       Auto-Select    1.82 TB

我能想到的最简单的事情是运行状态Lost Communication

#Single out the disk that has lost communication
Get-PhysicalDisk | Where-Object { $_.OperationalStatus -eq 'Lost Communication' }

从那里我可以将该磁盘分配给一个变量:

#Assign the missing disk to a variable
$missingDisk = Get-PhysicalDisk | Where-Object { $_.OperationalStatus -eq 'Lost Communication' }

现在我有一个变量对象,我可以将该磁盘标记为已退役:

#tell the storage pool that the disk has been retired:
$missingDisk | Set-PhysicalDisk -Usage Retired

最后,修复存储空间中所有受影响的卷:

# To Repair all Warning Volumes
Get-VirtualDisk | Where-Object –FilterScript {$_.HealthStatus –Eq 'Warning'} | Repair-VirtualDisk

您可以通过查看虚拟磁盘的操作状态InService

#Disks will show as `InService` to let us know that they're currently being repaired
Get-VirtualDisks

FriendlyName      ResiliencySettingName  OperationalStatus  HealthStatus  IsManualAttach   Size
------------      ---------------------  -----------------  ------------  --------------   ----
Three-way mirror  Mirror                 InService          Warning       False           10 TB
PooledParityDisk  Parity                 InService          Warning       False           15 TB

最后,您可以监控修复的进度:

#Monitor the percentage of the repair
Get-StorageJob

Name          ElapsedTime  JobState  PercentComplete  IsBackgroundTask
----          -----------  --------  ---------------  ----------------
Regeneration  00:00:00     Running   40               True
Regeneration  00:00:00     New       0                True

谢谢马修·霍奇金斯档案

附言认为 PowerShell 是个好主意的人应该被枪毙

答案3

当我遇到此问题时,我转向 Select-Object (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7

这不是很优雅,但如果您可以列出您的对象并且知道您只想要特定的对象,那么您可以使用 Select-Object 对它们进行数组索引。

即如果你想在第三个硬盘上操作:

获取物理磁盘 | 选择对象 -索引 2 | 设置物理磁盘…

相关内容