Create Local Admin User With Password Set To Never Expire

under Windows PowerShell Gist

 

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:

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")