如何在PowerShell中调用带有输出参数的方法?

问题描述:

我正在编写一个脚本以开始使用 PowerShell.我正在尝试转换一个 工作 VBScript 脚本,它枚举远程 Windows 上的映射网络驱动器电脑.

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.

其中一项任务是使用远程 WMI 读取注册表并找到进程所有者的 explorer.exe 以确定谁登录.这似乎很容易通过 本指南.

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.

但是,我需要调用的 WMI 方法是 GetOwner() 来自 Win32_Process,它需要两个输出参数来存储其返回值.

However, the WMI method I need to call is GetOwner() from Win32_Process, which requires two output parameters to store its return value.

如何调用带有输出参数的方法?当我尝试给它两个字符串时,出现错误:找不到GetOwner"的重载和参数计数:2"..MSDN 页面说有两个参数,所以我不确定我做错了什么.

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.