简体   繁体   中英

Cannot validate argument on parameter

To create a pool I am trying to select 4 disks out of 6.

I can get the list of UniqueIds as below:

PS C:\> 

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}

I can also choose the first four:

PS C:\> 

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

What I want to achieve is to select the disks I want, not the first 4 or all, but let's say disk numbers 1, 2, 4, 6 or UnıqueId starting with 3b34bfc1, 3b34bfc3, 3b34bfc7, 3b34bfcb.

You could try this:

$idFilter = '3b34bfc1', '3b34bfc3', '3b34bfc7', '3b34bfcb'
Get-PhysicalDisk -CanPool $true -HealthStatus 'Healthy' | 
     Where-Object { $idFilter -contains (($_.UniqueId).Substring(1, 8)) } | 
     Select -First 4

Using your examples, this would return:

 UniqueId FriendlyName SerialNumber CanPool OperationalStatus HealthStatus Usage Size -------- ------------ ------------ ------- ----------------- ------------ ----- ---- {3b34bfc1-1022-11e9-9df0-806e6f6e6963} VBOX HARDDISK True OK Healthy Auto-Select 5 GB {3b34bfc3-1022-11e9-9df0-806e6f6e6963} VBOX HARDDISK True OK Healthy Auto-Select 5 GB {3b34bfc7-1022-11e9-9df0-806e6f6e6963} VBOX HARDDISK True OK Healthy Auto-Select 5 GB {3b34bfcb-1022-11e9-9df0-806e6f6e6963} VBOX HARDDISK True OK Healthy Auto-Select 5 GB 

I was able to solve it :

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM