Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell-管道可枚举对象_Powershell - Fatal编程技术网

PowerShell-管道可枚举对象

PowerShell-管道可枚举对象,powershell,Powershell,具体来说,我的示例是MSMQ队列。考虑以下事项: Add-Type System.Messaging [System.Messaging.MessageQueue]::GetPrivateQueuesByMachineName('.') | gm 实际上,管道输出的是队列中的消息,而不是人们所期望的MessageQueue对象本身。我假设这是因为MessageQueue是可枚举的 如何强制PowerShell对MessageQueue对象本身进行管道传输并防止其枚举它们?您应该能够通过在前面加

具体来说,我的示例是MSMQ队列。考虑以下事项:

Add-Type System.Messaging
[System.Messaging.MessageQueue]::GetPrivateQueuesByMachineName('.') | gm
实际上,管道输出的是队列中的消息,而不是人们所期望的
MessageQueue
对象本身。我假设这是因为
MessageQueue
是可枚举的


如何强制PowerShell对
MessageQueue
对象本身进行管道传输并防止其枚举它们?

您应该能够通过在前面加逗号来强制PowerShell保持数组的完整性:

,[System.Messaging.MessageQueue]::GetPrivateQueuesByMachineName('.') | gm

您应该能够通过在PowerShell前面加逗号来强制它保持数组的完整性:

,[System.Messaging.MessageQueue]::GetPrivateQueuesByMachineName('.') | gm

另一个选项是在Get成员上使用
-InputObject
参数,因为它不会展开对象,例如:

Get-Member -InputObject ([Messaging.MessageQueue]::GetPrivateQueuesByMachineName('.'))

是的,这实际上完全避免了管道,但这是一种很好的技巧,可以在你的PowerShell技巧包中使用。

另一个选项是在Get成员上使用
-InputObject
参数,因为它不会展开对象,例如:

Get-Member -InputObject ([Messaging.MessageQueue]::GetPrivateQueuesByMachineName('.'))

是的,这实际上完全避免了管道,但这是一种很好的技术,可以在你的PowerShell技巧包中使用。

这当然有效,但它是通过将原始阵列放入新阵列中来实现的。然后管道展开新数组,并沿管道发送单个项。单个项目就是原始数组。这当然有效,但它是通过将原始数组放入新数组中来实现的。然后管道展开新数组,并沿管道发送单个项。作为原始数组的单个项。