【发布时间】:2015-04-16 09:32:38
【问题描述】:
我喜欢使用 PowerShell 查找驻留在 iSCSI 磁盘上的所有磁盘分区。
要查找我们可以使用的所有 iSCSI 磁盘对象 ID:
Get-Disk | Where BusType -ieq iscsi | Select -prop ObjectId
使用in 运算符,这应该返回所有分区:
Get-Partition | Where DiskId in (Get-Disk | Where BusType -ieq iscsi | Select -prop ObjectId)
不幸的是,这个命令返回一个典型的 PowerShell 错误:
Where-Object : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:1 char:17
+ Get-Partition | Where DiskId in (Get-Disk | Where BusType -ieq iscsi | Select -p ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WhereObjectCommand
如何正确使用in 运算符?
【问题讨论】:
-
注意运算符是
-in,而不是in。