Search code examples
c#powershellpowershell-sdk

Running PowerShell Script from C# has no effect


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!


Solution

  • Add -Force flag to the command

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