如何在PowerShell中调用带有输出参数的方法?
我正在编写一个脚本来开始使用 PowerShell。 我正在尝试转换工作 VBScript 脚本,该脚本枚举远程 Windows 上的映射网络驱动器电脑。
其中一项任务是使用远程 WMI 读取注册表并查找资源管理器的进程所有者。 exe 以确定谁已登录。这似乎很容易 本指南。
但是,我需要调用的 WMI 方法是 GetOwner() 来自Win32_Process,需要两个输出参数来存储其返回值。
如何调用带有输出参数的方法? 当我尝试给它两个字符串时,出现错误:找不到“GetOwner”的重载和参数计数:“2”。
。 MSDN 页面说有两个参数,所以我不确定我做错了什么。
I'm working on a script to get started in PowerShell. I'm trying to convert a working VBScript script that enumerates mapped network drives on a remote Windows computer.
One of the tasks is to use remote WMI to read the registry and find the process owner of explorer.exe in order to determine who is logged in. This seems easy enough going by this guide.
However, the WMI method I need to call is GetOwner() from Win32_Process, which requires two output parameters to store its return value.
How can I call a method with output parameters? When I try to give it two strings, I get the error: Cannot find an overload for "GetOwner" and the argument count: "2".
. The MSDN page says there are two parameters, so I'm not sure what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
[ref]
修饰符:著名博客条目
Using the
[ref]
modifier:Notable blog entries
在我看来,问题本质上是关于如何从函数返回多个变量(2 个输出参数)。 我知道这是一个老问题,但为了其他人来这里寻求答案,这里有几个选项:
在每种情况下,输出都具有相同的值。
您可能需要使用一个或另一个选项,具体取决于您调用的函数、是否可以修改该函数以及脚本的上下文。
It seems to me the question is essentially regarding how to return more than one variable from a function (2 output parameters). I know this is an old question, but for the sake of anyone else coming here for answers, here are several options:
In each case the output has the same values.
You may need to use one option or another depending on the function you're calling, whether or not you can modify the function, and based on the context of your script.