Guest User

Untitled

a guest
Aug 4th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. $output = ""
  2. "" | Out-File -FilePath "c:\scripts\output.txt"
  3. #$secpass = Read-Host "Password" -AsSecureString
  4. Import-Csv C:\scripts\attributetest.csv |
  5. foreach {
  6. $name = "$($_.FirstName) $($_.LastName)"
  7. $SamAccountName = "$($_.FirstName)$($_.LastName)"
  8. $Password = "$($_.Password)"
  9. $user = Get-ADUser -filter {SamAccountName -eq $SamAccountName}
  10. $ProxyAddress = ("SMTP:$SamAccountName@ryan.test.com")
  11. $ProxyAddress2 = ("smtp:$SamAccountName@hogarthww.mail.onmicrosoft.com")
  12. $TargetAddress = ("SMTP:$SamAccountName@hogarthww.mail.onmicrosoft.com")
  13. $ddmm = (Get-Date -UFormat "%d%m")
  14. $email = "$($_.FirstName.ToLower()).$($_.LastName.ToLower())@hogarthww.com"
  15.  
  16. if($user) {
  17. $SamAccountName = "$($_.FirstName)$($_.LastName)$ddmm"
  18. $name = "$($_.FirstName) $($_.LastName)$ddmm"
  19. $ProxyAddress = "SMTP:$($_.FirstName)$($_.LastName)$ddmm@hogarthww.com"
  20. $ProxyAddress2 = "smtp:$($_.FirstName)$($_.LastName)$ddmm@hogarthww.mail.microsoft.com"
  21. $email = "$($_.FirstName.ToLower()).$($_.LastName.ToLower())$ddmm@hogarthww.com"
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. New-ADUser -GivenName $($_.FirstName) -Surname $($_.LastName) `
  29. -name $name -SamAccountName $SamAccountName -UserPrincipalName "$($SamAccountName)@ryan.test.com" `
  30. -OtherAttributes @{'ProxyAddresses'=("$ProxyAddress"),"$ProxyAddress2"} `
  31. -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -Path "ou=Users,ou=HogarthWW,dc=ryan,dc=test,dc=com" `
  32. -Enabled:$true
  33.  
  34. $output += "User account has been created, details are as follows:`r`n`r`nemail: $email`r`nlogin:`r`npassword:$Password`r`n`r`nThanks,`r`nRyan.`r`n`r`n`r`n"
  35.  
  36.  
  37.  
  38. }
  39. $output | Out-File -FilePath "c:\scripts\output.txt"
  40. c:\scripts\output.txt
Add Comment
Please, Sign In to add comment