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.";
}
}