Advertisement
Guest User

Untitled

a guest
Mar 10th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. Import-Module ActiveDirectory
  2. #Create new password
  3. $securePassword = ConvertTo-SecureString "TESTpassw0rd!" -AsPlainText -Force
  4.  
  5. #Prompt user for CSV file path
  6. $filepath = Read-Host -Prompt "Please enter the path your CSV file"
  7.  
  8. #Import file into a variable
  9. $users = Import-Csv $filepath
  10.  
  11. #Loop thru each row and gather info
  12. ForEach ($user in $users) {
  13.  
  14. $fname = $user.'First Name'
  15. $lname = $user.'Last Name'
  16. $OUpath= $user.'Organizational Unit'
  17.  
  18. #Create new AD user for each user in CSV File
  19. New-ADUser -Name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincipalName "$fname.$lname" -Path $OUpath -AccountPassword $securePassword -ChangePasswordAtLogon $True
  20.  
  21. echo "Account created for $fname $lname in $OUpath"
  22. }
  23.  
  24. Import-Module : The specified module 'ActiveDirectory' was not loaded because no valid mod
  25. ule file was found in any module directory.
  26. At line:1 char:14
  27. + Import-Module <<<< ActiveDirectory
  28. + CategoryInfo : ResourceUnavailable: (ActiveDirectory:String) [Import-Modul
  29. e], FileNotFoundException
  30. + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.Import
  31. ModuleCommand
  32.  
  33. The term 'New-ADUser' is not recognized as the name of a cmdlet, function, script file, or
  34. operable program. Check the spelling of the name, or if a path was included, verify that
  35. the path is correct and try again.
  36. At line:19 char:14
  37. + New-ADUser <<<< -Name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincip
  38. alName "$fname.$lname" -Path $OUpath -AccountPassword $securePassword -ChangePasswordAtLog
  39. on $True
  40. + CategoryInfo : ObjectNotFound: (New-ADUser:String) [], CommandNotFoundExce
  41. ption
  42. + FullyQualifiedErrorId : CommandNotFoundException
  43.  
  44. Account created for User1 1 in OU=Sales,OU=Admin,OU=Clients
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement