Automate Creation/Update of local Admin Account in diffrent OS languages

How do you address the issue of automating the management of local administrator accounts on bilingual (French/English) operating systems? Specifically, how do you ensure that a new administrator account is created if it doesn’t already exist, or updated with a new password if necessary? What’s more, how do you manage the added complexity introduced by the fact that the name of the administrator group differs according to the operating system (Administrators vs. Administrateurs)? This question raises important challenges in terms of security and operational efficiency.

the solution lies in this PowerShell script 💪💪💪

simply replace your local admin account name and password in the two variables “$userName” and “$Password”.

This script must be executed as system or Administrator

Set-ExecutionPolicy RemoteSigned -Force

# Define ErrorActionPreference
$ErrorActionPreference= 'silentlycontinue'

# Define admin username
$userName = 'admin2'

# Define admin Password
$Password = ConvertTo-SecureString 'P@ssw0rd' -AsPlainText -Force

# Define administrator Group name -- English  version
$Group = "Administrators"

if(!((Get-LocalGroup | Select Name | where Name -like "Administrat*").Name -contains $Group))
{
    # Define administrator Group name -- French version
    $Group = "Administrateurs"
}

if((Get-LocalUser).Name -Contains $userName)
{   
    # if the account exist then update the the account with new password and new settings
    Set-LocalUser -Name $userName -Password $Password -PasswordNeverExpires  -AccountNeverExpires
    Add-LocalGroupMember -Member $userName -Group $Group
    Write-Host "User $userName updated Successfully............." -ForegroundColor yellow
}
else
{
    # if the username not exist then create new one
    New-LocalUser -Name $userName -Password $Password -FullName "$($userName)" -Description "local Admin Account" -PasswordNeverExpires  -AccountNeverExpires | Add-LocalGroupMember -Group $Group
    Write-Host "User $userName Created Successfully............." -ForegroundColor green
} 

here is the result if the user account doesnt exist :

and here’s the result if the account already exists :

Thanks

Aymen EL JAZIRI (Microsoft MVP)
Aymen EL JAZIRI (Microsoft MVP)

Hi, I’m Aymen El Jaziri , a passionate System Administrator and Microsoft MVP, with years of hands-on experience in managing and securing modern IT infrastructures.
This blog is where I share technical guides, automation scripts, product reviews, and real-world solutions that help IT professionals simplify their day-to-day work and stay ahead in a fast-evolving cloud ecosystem.
Whether you’re here to troubleshoot an issue, improve your automation game, or learn new best practices , welcome in my blog !
Let’s build a stronger, smarter IT community together.
Feel free to connect with me on LinkedIn for more content, discussions, or collaboration opportunities.

Thanks

Aymen

Articles: 154