0

I have created the following C# code to run a powershell script:

static void Main(string[] args)
        {

            PowerShell ps = PowerShell.Create();
            string script = "";
            script = "Set-WinUserLanguageList -LanguageList en-US,de-DE,uk ";
            ps.AddScript(script);
            var result = ps.Invoke();

            Console.WriteLine(result);
            Console.ReadLine();
        }

If I run Set-WinUserLanguageList -LanguageList en-US,de-DE,uk from PowerShell, it is working fine and my windows language list changes in the defined order (EN,GER,UK). But if I run my C# code nothing happens.

I checked Google but couldn't find any vital difference...

Anyone has an idea what I have to change in my C# code to make it working?

Thanks!

1
  • 1
    When you use .AddScript(), any errors that occur during execution of the PowerShell code do not surface as exceptions in your C# program; instead, you must examine the .Streams.Error collection (.HadErrors is a Boolean that indicates whether any errors occurred) - see this answer for details. Commented Apr 25, 2023 at 12:35

1 Answer 1

1

Add -Force flag to the command

i.e Set-WinUserLanguageList -Force -LanguageList en-US,de-DE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.