Set via C# Powershell Variable

Question:

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:
Products

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#?

Answer:

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:

Source:

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

Leave a Reply