first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

PowerShell 1 Script: Add Local Users; ADSI; Active Directory; Add-LocalUser

Clear-Host;

Function Add-LocalUser([String]$userName, [String]$userDescription, [String]$password) { $path = [String]::Concat("WinNT://./",$userName,",user"); $user = [ADSI]$path; if([String]::IsNullOrEmpty($user.Name)) { $computer = [ADSI]"WinNT://."; $user = $computer.Create("user", $userName); $user.SetPassword($password); $user.SetInfo(); $user.Description = $userDescription; $user.SetInfo(); $user.UserFlags += 65536 #flag ADS_UF_DONT_EXPIRE_PASSWD = &h10000

	$user.SetInfo();

	Write-Host "User"$user.Name"added.";
}
else
{
	Write-Host "User"$user.Name"already a Local User.";
}

}

Add-LocalUser "MyUser" "Local Account" "my1passw0rd";

mod date: 2009-03-19T03:39:25.000Z