0

我喜欢使用 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正确使用运算符?

4

1 回答 1

0

select -prop ObjectId不按你的想法做。它创建一个具有属性子集的新对象。

改为使用select -exp ObjectId。它返回属性值本身,而不将它们包装在自定义对象中。

Get-Partition | Where DiskId -in (Get-Disk | Where BusType -ieq iscsi | Select -exp ObjectId)
于 2015-04-16T09:45:31.753 回答