首页 > 解决方案 > 根据值从数组中选择一组值

问题描述

我正在使用以下 PowerShlell 来获取可用物理磁盘的列表。

$disks=((Get-PhysicalDisk -CanPool $true)|Select-Object PhysicalLocation) 

上面代码的输出如下图

集成:适配器 3:端口 0:目标 0:LUN 7

集成:适配器 3:端口 0:目标 0:LUN 0

集成:适配器 3:端口 0:目标 0:LUN 5

集成:适配器 3:端口 0:目标 0:LUN 2

集成:适配器 3:端口 0:目标 0:LUN 6

集成:适配器 3:端口 0:目标 0:LUN 4

集成:适配器 3:端口 0:目标 0:LUN 1

集成:适配器 3:端口 0:目标 0:LUN 3

集成:适配器 3:端口 0:目标 0:LUN 8

但是,从集合中我想选择一组 LUN,例如从 5 到 8 的 LUN 来创建一个存储池,使用

新存储池

谢谢

标签: powershell

解决方案


您不需要将表达式放在括号中。您可以尝试以下方法。此正则表达式将帮助您获得所需的结果。

Get-PhysicalDisk -CanPool $true | Foreach-Object -Process {
   $_.PhysicalLocation | Select-String -Pattern 'LUN.[5-8]'
}

推荐阅读