Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# show current user list
PS C:\Users\Administrator> Get-ADUser -Filter * | Format-Table DistinguishedName
DistinguishedName
-----------------
CN=Administrator,CN=Users,DC=srv,DC=world
CN=Guest,CN=Users,DC=srv,DC=world
CN=krbtgt,CN=Users,DC=srv,DC=world
CN=Server World,CN=Users,DC=srv,DC=world
# for example, add [ADUser01] user
PS C:\Users\Administrator> New-ADUser ADUser01 `
-Surname ADUser01 `
-GivenName ADUser01 `
-DisplayName "AD User01" `
-EmailAddress "ADUser01@srv.world" `
-AccountPassword (ConvertTo-SecureString -AsPlainText "P@ssw0rd01" -Force) `
-ChangePasswordAtLogon $true `
-Enabled $true
# verify
PS C:\Users\Administrator> Get-ADUser -Identity ADUser01
DistinguishedName : CN=ADUser01,CN=Users,DC=srv,DC=world
Enabled : True
GivenName : ADUser01
Name : ADUser01
ObjectClass : user
ObjectGUID : ca7d1690-8b45-48e4-bb24-deb71260c638
SamAccountName : ADUser01
SID : S-1-5-21-2649012655-406810028-4197379243-1106
Surname : ADUser01
UserPrincipalName :
# with specify [OU], run like follows
PS C:\Users\Administrator> New-ADUser ADUser02 `
-Path "OU=Hiroshima,DC=srv,DC=world" `
-Surname ADUser02 `
-GivenName ADUser02 `
-DisplayName "AD User02" `
-EmailAddress "ADUser02@srv.world" `
-AccountPassword (ConvertTo-SecureString -AsPlainText "P@ssw0rd02" -Force) `
-ChangePasswordAtLogon $true `
-Enabled $true
# to reset existing user's password, run like follows
PS C:\Users\Administrator> Set-ADAccountPassword -Identity ADUser02 `
-NewPassword (ConvertTo-SecureString -AsPlainText "UserP@ssw0rd02" -Force) `
-Reset
# to delete a user, run like follows
PS C:\Users\Administrator> Remove-ADUser -Identity "CN=ADUser02,OU=Hiroshima,DC=srv,DC=world"
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove" on target "CN=ADUser02,OU=Hiroshima,DC=srv,DC=world".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
|