Forum Discussion
Todd_Lange
Jan 21, 2022Copper Contributor
How can I filter the result of Get-PhysicalDisk by both CanPool=$True and IsPartial=$False
I'm just learning PowerShell, so I'm a bit green.
I want to filter the output of Get-PhysicalDisk by 'CanPool=$True and IsPartial=$False' and use that as the input argument to New-StoragePool in the -PhysicalDisks argument.
I can use the -CanPool argument, but I also need to exclude items where IsPartial=$False
This works fine when just filtering by CanPool:
$PhysicalDisks = Get-PhysicalDisk -CanPool $true
$StoragePool = New-StoragePool -FriendlyName "DataStoragePool" -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks $PhysicalDisks
I've tried this to filter by CanPool and IsPartial but I get a conversion error in the call to New-StoragePool.
$PhysicalDisks = Get-PhysicalDisk | Select-Object FriendlyName, SerialNumber, CanPool, Size, IsPartial | Where-Object {$_.IsPartial -eq $False -and $_.IsPartial -eq $False}
$StoragePool = New-StoragePool -FriendlyName "DataStoragePool" -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks $PhysicalDisks
The error I get is this:
New-StoragePool : Cannot process argument transformation on parameter 'PhysicalDisks'. Cannot convert the "@{FriendlyName=NVMe
Amazon Elastic B; SerialNumber=vol0e91db9293994ab3a_00000001.; CanPool=True; Size=53687091200; IsPartial=False}" value of type
"Selected.Microsoft.Management.Infrastructure.CimInstance" to type "Microsoft.Management.Infrastructure.CimInstance".
At C:\Viavi\PowerShell\CreateDataVolume.ps1:59 char:132
+ ... ubsystemFriendlyName "Windows Storage*" -PhysicalDisks $PhysicalDisks
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-StoragePool], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,New-StoragePool
There must be an easy way to do this? Any suggestions?
2 Replies
- Jonathan_AllenBrass Contributor
(Not got any disks I can check your parameter values on here) Does this give you a boost ?
Get-PhysicalDisk -CanPool $false |where {-not $_.ispartial }
- Todd_LangeCopper Contributor
FYI - Maybe not very elegant, but I found this works:
$PhysicalDisks = Get-PhysicalDisk -CanPool $true $PhysicalDisksFiltered = @() foreach ($disk in $PhysicalDisks) { if ($disk.IsPartial -ne $true) { $PhysicalDisksFilter += $disk } } $StoragePool = New-StoragePool -FriendlyName "DataStoragePool" -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks $PhysicalDisksFiltered