The following script will create a local computer users in windows, set it’s password, mark the password to not expire and optionally set the description:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
param($computer="localhost", $user, $password,$description) if(!$user -or !$password) { $(Throw '$user and $password is required.') } $objOu = [ADSI]"WinNT://$computer" $objUser = $objOU.Create("User", $user) $objUser.put("description",$description) $objUser.setpassword($password) $objUser.UserFlags.value = $objUser.UserFlags.Value -bor 65536 # ADS_USERFLAG_DONT_EXPIRE_PASSWD $objUser.SetInfo() $group = [ADSI]("WinNT://$computer/administrators,group") $group.add("WinNT://$user,user") |