调用管道对象上的属性/方法 [英] Call the properties/methods on the Piped Object

查看:42
本文介绍了调用管道对象上的属性/方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解如何管道|一个对象并调用它的属性或方法.

I am trying to understand how to pipe | an object and call the properties or methods on that.

Ex:
$a = Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\
$a.GetSomething()  //calls the method
(Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\).GetSomething() //calls the method

我可以通过管道传输 Get-Item 的输出并在其上invoke properties/methods 吗?

Can I pipe the output of the Get-Item and invoke properties/methods on it?

Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\ | call GetSomething()

推荐答案

简短的回答是.您不能使用 Pipeline 调用这样的方法.但是您可以将您的 Get-Item 调用括在括号中并调用它:

The short answer is no. You can't call a method like this using Pipeline. But you can surround your Get-Item invoke in parentheses and invoke it:

(Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\).GetSomething()


如果您不希望那样,您可以滥用 Select-Object cmdlet:

Get-Item Registry::HKLM\SOFTWARE\WOW6432Node\Microsoft\Test\abc\  | select { $_.GetSomething() }

这篇关于调用管道对象上的属性/方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆