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

PowerShell 1.0: Add a Local User; Add-LocalUser Function; ADSI

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

}

mod date: 2009-08-02T01:36:35.000Z