2016-06-24 3 views

答えて

1

PSCmdlet.GetVariableValue(string)方法がこのために使用することができる。PowerShell内

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); 
     } 
    } 
} 

テスト:同じ `PSHost`が複数の` Runspace`を有することができる

PS > Test-GetVariableValueMethod 
High 

PS > $ConfirmPreference = 'Low' 

PS > Test-GetVariableValueMethod 
Low 
関連する問題