powershell - 根据值从数组中选择一组值
问题描述
我正在使用以下 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 来创建一个存储池,使用
新存储池
谢谢
解决方案
您不需要将表达式放在括号中。您可以尝试以下方法。此正则表达式将帮助您获得所需的结果。
Get-PhysicalDisk -CanPool $true | Foreach-Object -Process {
$_.PhysicalLocation | Select-String -Pattern 'LUN.[5-8]'
}
推荐阅读
- javascript - Plotly Dash:dash_bootstrap_components.Collapse 不折叠
- microprofile - 多个 Microprofile 实现的单一代码库
- reactjs - 使用标头中使用的状态并基于带有钩子的 Route 更新其内容
- react-native - 滚动在 React Native 中的多行水平 FlatList 中不起作用
- azure - 如何在 Azure 数据工厂中进行 Blob 存储到 API 数据传输?
- python - 同时遍历两个字符串列表
- twilio - 使用 Flex 和 webhook 捕获 Twilio 消息历史记录
- javascript - 编辑gridview中的ASP.NET C#签名画布
- html - 空的时候怎么隐藏
- javascript - styled(MyComponent) 呈现 MyComponent 但没有其他样式