more specific I want to access the value of the ErrorAction parameter from withing the cmdlet.
In powershell everything works as expected
function Get-Test {
[CmdletBinding()]
param (
)
(Get-Variable|where{$_.Name -eq "ErrorActionPreference"}).Value
}
Get-Test -ErrorAction SilentlyContinue
will output SilentContinue
However the same call in c# will output Continue
[CmdletBinding]
[Cmdlet(VerbsCommon.Get,"Test")]
public class MyClass:PSCmdlet{
protected override void ProcessRecord(){
base.ProcessRecord();
WriteObject(((PSVariable) InvokeCommand.InvokeScript($"Get-Variable|where{{$_.Name -eq 'ErrorActionPreference'}}").First().BaseObject).Value);
}
}
it looks like there is no link between the ErrorAction parameter and the ErrorActionPreference when c#. I say this because if I do
$ErrorActionPreference="SilentlyContinue"
Get-Test # c# version
will output SilentlyContinue