1

$ConfirmPreferenceC# で記述されたバイナリ Powershell モジュール内から Powershell ホストなどからグローバル変数の値を取得するにはどうすればよいですか?

4

1 に答える 1

2

メソッドはこれPSCmdlet.GetVariableValue(string)に使用できます。

using System.Management.Automation;

namespace MyModule
{

    [Cmdlet(VerbsDiagnostic.Test, "GetVariableValueMethod")]
    public class TestGetVariableValueMethod : PSCmdlet
    {
        protected override void ProcessRecord()
        {
            ConfirmImpact confirmPref =
                (ConfirmImpact)this.GetVariableValue("global:ConfirmPreference");
            WriteObject(confirmPref);
        }
    }
}

Powershell 内でのテスト:

PS > Test-GetVariableValueMethod
High

PS > $ConfirmPreference = 'Low'

PS > Test-GetVariableValueMethod
Low
于 2016-06-24T14:20:44.590 に答える