Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Username = $User.username
- $Password = $User.password
- $Firstname = $User.firstname
- $Lastname = $User.lastname
- $OU = $User.ou #This field refers to the OU the user account is to be created in
- $email = $User.email
- $Password = $User.Password
- $groups = $User.groups
- #Check to see if the user already exists in AD
- if (Get-ADUser -F {SamAccountName -eq $Username})
- {
- #If user does exist, give a warning
- Write-Warning "A user account with username $Username already exist in Active Directory."
- }
- else
- {
- #User does not exist then proceed to create the new user account
- #Account will be created in the OU provided by the $OU variable read from the CSV file
- New-ADUser `
- -SamAccountName $username `
- -UserPrincipalName "$username@lon.deloitterisk.cloud" `
- -Name "$Firstname $Lastname" `
- -GivenName $Firstname `
- -Surname $Lastname `
- -Enabled $True `
- -DisplayName "$Lastname, $Firstname" `
- -Path $OU `
- -AccountPassword (convertto-securestring $Password -AsPlainText -
- Force) -ChangePasswordAtLogon $False -PasswordNeverExpires:$True `
- -group
- {
- foreach($groups in $ADUsers)
- {
- $Username = $User.username
- $groups = $User.groups -split ","
- foreach ($group in $groups)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement