Help with Swedish Group Names in Windows Powershell

0
0
Asked By TechTinkerer99 On

I'm encountering issues with a group name that's based on the system language in Windows. Specifically, it seems like the character "ä" in the group name isn't being recognized correctly, which leads me to think it might be a formatting problem. I'm working with a file that is saved in UTF-8 format, and the PowerShell script I'm using includes a switch statement that assigns group names based on the operating system's language. Here's the code I'm using:

```powershell
$systemLanguage = (Get-WmiObject -Class Win32_OperatingSystem).OSLanguage

switch ($systemLanguage) {
1033 { $groupName = "Network Configuration Operators" }
1053 { $groupName = "Ansvariga för nätverkskonfigurering" }
default {
$groupName = "Network Configuration Operators"
}
}

try {
$addResult = net localgroup "`"$groupName`"" "`"$formattedUser`"" /add
} catch {
Write-Host "Error adding user to group: $($_.Exception.Message)"
}
```

What can I do to resolve this issue?

5 Answers

Answered By CodeChameleon On

Have you tried saving your file with UTF-8 BOM? It usually helps with characters like ä, ø, å for me!

TechTinkerer99 -

Like magic, thanks a lot! 🙂

Answered By ScriptSage On

These groups have a well-known SID, which allows you to identify them by SID rather than worrying about localized names. You could try using S-1-5-32-556 for your group. For further details, check the Microsoft documentation!

Answered By PowerShellPro On

Just a heads-up, `Get-WmiObject` is considered legacy now, so you might want to switch to `Get-CIMInstance`. Also, instead of using localized names, consider using the well-known SID for the group; it's consistent and avoids language issues. Also, you might want to use `Get-LocalGroup` instead of `net localgroup` for better compatibility.

TechTinkerer99 -

Thanks a lot for the heads up and advice! I’ll definitely explore using SIDs moving forward! 🙂

Answered By ByteBard On

Using the well-known SID is a great approach! It can eliminate issues related to localization completely. Just ensure you're using the correct SID, and you should be set!

Answered By SIDMaster On

That group is referenced by the well-known SID S-1-5-32-556, which is culture independent. You can use this in your script like this: `Get-LocalGroup -sid S-1-5-32-556`, and just use the SID to add group members instead of the display name.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.