Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Imports users from HR csv and which creates an object with properties that match the column headers
- $users = Import-Csv -Path 'C:\Path\to\CSV'
- #Defines the default password for new accounts
- $AccountPassword = $(ConvertTo-SecureString -String "New User Default Password" -AsPlainText -Force)
- #Loops through each row in the csv, creates variable for each property it got from the csv and then creates the user.
- foreach ($user in $users){
- #These match the column names in the csv
- $NewUserSplat = @{
- SamAccountName = $user.Username
- Name = "$($user."Last Name"), $($user."First Name") $($user.Int)."
- GivenName = $user."First Name"
- Surname = $user."Last Name"
- Initials = $user.Int
- DisplayName = "$($user."Last Name"), $($user."First Name") $($user.Int)."
- UserPrincipalName = "$($user.Username)@company.org"
- Description = "$($user."Position") - $($user."Department")"
- EmployID = $user."ID"
- OU = "ou=OU,dc=company,dc=org"
- Enabled = $true
- CannotChangePassword = $false
- ChangePasswordAtLogon = $true
- AccountPassword = $AccountPassword
- }
- #Creates the user in AD
- $NewUser = New-ADUser @NewUserSplat -PassThru
- $NewUserName = Get-ADUser -Identity $NewUser
- #Adds the new user we just created to group one
- $GroupOne = 'group one'
- Add-ADGroupMember -Identity $GroupOne -Members $NewUserName
- #Adds new user we just created to group two
- $GroupTwo = 'group two'
- Add-ADGroupMember -Identity $GroupTwo -Members $NewUserName
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement