要创建一个池,我试图从6个磁盘中选择4个磁盘。
我可以得到如下的UniqueIds列表:
PS C:\> Get-PhysicalDisk|? Canpool|ft UniqueId UniqueId -------- {3b34bfc1-1022-11e9-9df0-806e6f6e6963} {3b34bfc3-1022-11e9-9df0-806e6f6e6963} {3b34bfc5-1022-11e9-9df0-806e6f6e6963} {3b34bfc7-1022-11e9-9df0-806e6f6e6963} {3b34bfc9-1022-11e9-9df0-806e6f6e6963} {3b34bfcb-1022-11e9-9df0-806e6f6e6963}
我也可以选择前四个:
PS C:\> Get-PhysicalDisk |? CanPool|? HealthStatus| select -first 4 FriendlyName SerialNumber CanPool OperationalStatus HealthStatus Usage Size ------------ ------------ ------- ----------------- ------------ ----- ---- VBOX HARDDISK True OK Healthy Auto-Select 5 GB VBOX HARDDISK True OK Healthy Auto-Select 5 GB VBOX HARDDISK True OK Healthy Auto-Select 5 GB VBOX HARDDISK True OK Healthy Auto-Select 5 GB
我要实现的是选择我想要的磁盘,而不是前4个或全部,但是假设以1b,2、4、6或UnıqueId为开头的磁盘编号为3b34bfc1、3b34bfc3、3b34bfc7、3b34bfcb。
答案 0 :(得分:0)
您可以尝试以下方法:
%dw 1.0
%input payload application/json
%output application/json
---
payload pluck ((value,key) -> {
name: key,
max: value.Max,
remaining: value.Remaining
}
)
使用您的示例,它将返回:
$idFilter = '3b34bfc1', '3b34bfc3', '3b34bfc7', '3b34bfcb' Get-PhysicalDisk -CanPool $true -HealthStatus 'Healthy' | Where-Object { $idFilter -contains (($_.UniqueId).Substring(1, 8)) } | Select -First 4
答案 1 :(得分:0)
我能够解决它:
PS C:\Users\Administrator> Get-PhysicalDisk|? Canpool|ft UniqueId
UniqueId
--------
{78f3d471-15cb-11e9-9df3-806e6f6e6963}
{78f3d472-15cb-11e9-9df3-806e6f6e6963}
{78f3d473-15cb-11e9-9df3-806e6f6e6963}
{78f3d474-15cb-11e9-9df3-806e6f6e6963}
{78f3d475-15cb-11e9-9df3-806e6f6e6963}
{78f3d476-15cb-11e9-9df3-806e6f6e6963}
PS C:\Users\Administrator> Get-PhysicalDisk|? Canpool|? {"{78f3d471-15cb-11e9- 9df3-806e6f6e6963};{78f3d472-15cb-11e9-9df
3-806e6f6e6963}".Contains($_.UniqueId)}
FriendlyName SerialNumber CanPool OperationalStatus HealthStatus Usage Size
------------ ------------ ------- ----------------- ------------ ----- ----
VBOX HARDDISK True OK Healthy Auto-Select 5 GB
VBOX HARDDISK True OK Healthy Auto-Select 5 GB