gpt4 book ai didi

powershell - 如何从C#PowerShell命令向PowerShell返回值或对象?

转载 作者:行者123 更新时间:2023-12-02 23:47:09 27 4
gpt4 key购买 nike

我将C#库(.NET 4)与System.Management.Automation DLL文件一起使用,以实现PowerShell(2.0)的某些命令。

我需要从PowerShell脚本中的命令获取值。

[Cmdlet(VerbsCommon.Get, "MyCommand")]
public class GetMyCommand : Cmdlet
{
protected override void ProcessRecord()
{
// How do I return a value to PowerShell?
}
}

我想要获得值(value)的方式是这样的:
$value = Get-MyCommand

最佳答案

您必须使用CmdLet.WriteObject方法。

Here is来自@RomanKuzmin的很好的解释。

关于powershell - 如何从C#PowerShell命令向PowerShell返回值或对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17468661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com