Active Directory User Management using Powershell
Active Directory User Management using Powershell
SamAccountName – Specifies the SAM Account name of the user. ”New-ADUser” command should have this parameter for creating a user. You can pass a string value in it.
DisplayName – Specifies the name to be displayed.
AccountPassword – Specifies the account password for the user. However, the password has to be provided after executing the command as a secured string. The default value for this parameter would be as follows. –AccountPassword (ReadHost –AsSecureString “Message”)
CannotChangePassword – Specifies whether the user can change the password or not. The two acceptable values will be $true and $false.
ChangePasswordAtLogon – Specifies whether the new user has to change the password on the first login or not. The two acceptable values will be $true and $false.
PasswordNeverExpires – Specifies whether the password will never expire. The two acceptable values will be $true and $false.
EmailAddress – Specifies the email address of the new user.
EmployeeID – Specifies the employee ID of the new user.
Edit department of bulk users using .csv file
$Users=import-csv "C:\Temp\filename.csv"
foreach ($user in $Users)
{
$ID = $user.SamAccountName
$Dep = $user.Department
Set-ADUser -Identity $ID -Department $Dep
}
Creating a Single User
New-ADUser –SamAccountName “username” –DisplayName “username”
–givenName “Username” –Surname “surname” –AccountPassword (ReadHost
–AsSecureString “Message”) –Enabled $true –Path ‘CN=Users, DC=Doc, DC=Com’
–CannotChangePassword $false –ChangePasswordAtLogon $true
–PasswordNeverExpires $false -EmailAddress “email” –EmployeeID “ID”
–Department “string”
Surname – Specifies the surname of the user.
Enabled – Specifies whether the new user will be enabled or disabled. If you’re not providing the password, then the user will be disabled by default. You can provide $true for true and $false for false.
Path – Specifies the path of Active Directory where the new user will be created. Its value should be passed between single quotes, such as –Path ‘CN=Users, DC=Domain, DC=Com’
Department – Specifies the department of the new user.
Creating Bulk Users
Create a CSV file for creating the bulk users through PowerShell using the Import-CSV CMDlet
Execute the following command
Import-CSV D:\add_users.csv | New-ADUser
Edit department of bulk users using .csv file
$Users=import-csv "C:\Temp\filename.csv"
foreach ($user in $Users)
{
$ID = $user.SamAccountName
$Dep = $user.Department
Set-ADUser -Identity $ID -Department $Dep
}
Comments
Post a Comment