# Configure properties Set-LocalUser -Name $UserName -PasswordNeverExpires $false -UserMayChangePassword $true
try # Create user $Password = Read-Host "Enter password for $UserName" -AsSecureString New-LocalUser -Name $UserName -Password $Password -FullName $FullName -ErrorAction Stop lusrmgr.exe
// Add to group DirectoryEntry adminGroup = localMachine.Children.Find("Administrators", "Group"); adminGroup.Invoke("Add", new object[] newUser.Path ); ' VBScript example Set objWMIService = GetObject("winmgmts:impersonationLevel=impersonate!\\.\root\cimv2") ' List users Set colAccounts = objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE LocalAccount=True") For Each objAccount in colAccounts WScript.Echo objAccount.Name & " - " & objAccount.FullName Next new object[] newUser.Path )
// Create user DirectoryEntry newUser = localMachine.Children.Add("JohnDoe", "User"); newUser.Properties["FullName"].Value = "John Doe"; newUser.Invoke("SetPassword", new object[] "P@ssw0rd" ); newUser.CommitChanges(); newUser.Properties["FullName"].Value = "John Doe"
foreach (DirectoryEntry user in users.Children)
# Add to group Add-LocalGroupMember -Group $GroupName -Member $UserName