I am executing a powershell script using C#, but when I try to get an environment variable inside the powershell script it does not work.
If I run the powershell script manually using the console it works.
Do you have any idea on how to solve this issue ?
Code sample for C#:
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
// set directory for ps
if (!string.IsNullOrEmpty(sessionPath))
runspace.SessionStateProxy.Path.SetLocation(sessionPath);
Pipeline pipeline = runspace.CreatePipeline();
Command command = new Command(script, false);
pipeline.Commands.Add(command);
pipeline.Commands.Add("Out-String");
pipeline.InvokeAsync();
script powershell:
$path = $env:PATH;
write-output $path # this is empty ! $env does seems to exist in the runspace ?