I'm trying to help my wife who is a teacher with setting up computers in her classroom. On each of these Windows 10 computers exactly the same set of local accounts should be created. I'm trying to prepare simple PowerShell script which will simply add all these users automatically after system installation. Unfortunately this is so screwed that I've already lost two days on such simple task.
Problem is that this is a polish version of Windows 10 and local users have to be members of "Users" group which is "Użytkownicy" in polish version of Windows.
Therefore, my PowerShell script looks like this:
$SecurePassword = ConvertTo-SecureString "Password" -AsPlainText -Force
New-LocalUser "Maluch" -Password $SecurePassword -FullName "Uczen" -Description "Uczen"
Add-LocalGroupMember -Group "Użytkownicy" -Member "Maluch"
Next, I run this script from cmd shell like this:
powershell.exe -ExecutionPolicy Bypass -File .\Add_Users.ps1
Unfortunately it drops such error:
Add-LocalGroupMember : Group UĹĽytkownicy -Member was not found.
At C:\install\Add_Users.ps1:3 char:1
+ Add-LocalGroupMember -Group `UĹĽytkownicy` -Member 'Maluch'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (UĹĽytkownicy -Member:String) [Add-LocalGroupMember], GroupNotFoundException
+ FullyQualifiedErrorId :
GroupNotFound,Microsoft.PowerShell.Commands.AddLocalGroupMemberCommand
I suppose the problem is that string "Użytkownicy" is encoded as UTF-8 which is not accepted as cmdlet parameter. For me it is quite shocking that programming language provided by Microsoft isn't compatible with their own operating system. Any idea how to prepare this script correctly?
Similarly I want to set password for one of users which contains UTF-8 chars in it:
$SecurePassword = ConvertTo-SecureString "trójka" -AsPlainText -Force
New-LocalUser "TestUser" -Password $SecurePassword -FullName "Test User" -Description "Test User"
This goes well within the script but later when I try to log-in to the "TestUser" account then it turns out that password is wrong. Probably due exactly the same problem as above.
Tried to change PowerShell behavior but any of below settings didn't help:
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
[Environment]::SetEnvironmentVariable("LC_ALL", "C.UTF-8", "User")
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding