Lusrmgr.exe: [portable]

// Create user DirectoryEntry newUser = localMachine.Children.Add("JohnDoe", "User"); newUser.Properties["FullName"].Value = "John Doe"; newUser.Invoke("SetPassword", new object[] "P@ssw0rd" ); newUser.CommitChanges();

$SecurePassword = Read-Host "Enter password" -AsSecureString New-LocalUser -Name "ServiceAccount" -Password $SecurePassword Automation Script Example # Complete user provisioning script param( [Parameter(Mandatory=$true)] [string]$UserName, [string]$FullName, [string]$GroupName = "Users" ) Elevation check if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File "$PSCommandPath " $UserName $FullName $GroupName" -Verb RunAs exit lusrmgr.exe

# Export all local users and groups $output = @() Get-LocalUser | ForEach-Object $output += [PSCustomObject]@ Username = $_.Name Enabled = $_.Enabled LastLogin = $_.LastLogon Groups = (Get-LocalGroup // Create user DirectoryEntry newUser = localMachine

Write-Host "User $UserName created successfully" -ForegroundColor Green catch Write-Host "Error: $_" -ForegroundColor Red newUser.Properties["FullName"].Value = "John Doe"

Write-Host "Run as Administrator required" -ForegroundColor Red exit 1

# Add to group Add-LocalGroupMember -Group $GroupName -Member $UserName

try # Create user $Password = Read-Host "Enter password for $UserName" -AsSecureString New-LocalUser -Name $UserName -Password $Password -FullName $FullName -ErrorAction Stop