Set via C# Powershell Variable


I have to set via C# a variable in PowerShell and have to use that variable via C# in Powershell again, my code so far:

In this case the output should be:

But this C# doesn’t work, i tired also:

But it works neither.
Has someone an idea how I could set a variable in Powershell and can work with it in Powershell always via C#?


In regards to setting a variable, your second code block works as expected, the following is a quick test setting $item in powershell to FooBar, pulling this back and confirming that the value is correct:

To work directly on Powershell from C#, the following should do the trick:


Set via C# Powershell Variable by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply