如何在PowerShell中调用带有输出参数的方法? [英] How to call a method with output parameters in PowerShell?

查看:64
本文介绍了如何在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.

推荐答案

使用 [ref] 修饰符

Using the [ref] modifier

SomeMethod( [ref] $a );

著名的博客条目

这篇关于如何在PowerShell中调用带有输出参数的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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