Posted in
Windows Powershell,
Windows Server |
4 Comments | 7,353 views | 23/06/2009 10:39
You can create Windows user from Powershell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| function create_user($username, $password)
{
$computer = [ADSI]"WinNT://localhost"
foreach ($user in $computer.psbase.children)
{
if ($user.Name -eq $username)
{
Write-Host $user.Name "already exist."
Return
}
}
$user_obj = $computer.Create("user", "$username")
$user_obj.Put("description", "$username")
$user_obj.SetInfo()
$user_obj.SetPassword($password)
$user_obj.SetInfo()
$user_obj.psbase.invokeset("AccountDisabled", "False")
$user_obj.SetInfo()
Write-Host "$username created."
}
create_user "$username" "$password" |
function create_user($username, $password)
{
$computer = [ADSI]"WinNT://localhost"
foreach ($user in $computer.psbase.children)
{
if ($user.Name -eq $username)
{
Write-Host $user.Name "already exist."
Return
}
}
$user_obj = $computer.Create("user", "$username")
$user_obj.Put("description", "$username")
$user_obj.SetInfo()
$user_obj.SetPassword($password)
$user_obj.SetInfo()
$user_obj.psbase.invokeset("AccountDisabled", "False")
$user_obj.SetInfo()
Write-Host "$username created."
}
create_user "$username" "$password"
It checks user and if it is not exist, creates that username.