Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module ActiveDirectory
- #Create new password
- $securePassword = ConvertTo-SecureString "TESTpassw0rd!" -AsPlainText -Force
- #Prompt user for CSV file path
- $filepath = Read-Host -Prompt "Please enter the path your CSV file"
- #Import file into a variable
- $users = Import-Csv $filepath
- #Loop thru each row and gather info
- ForEach ($user in $users) {
- $fname = $user.'First Name'
- $lname = $user.'Last Name'
- $OUpath= $user.'Organizational Unit'
- #Create new AD user for each user in CSV File
- New-ADUser -Name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincipalName "$fname.$lname" -Path $OUpath -AccountPassword $securePassword -ChangePasswordAtLogon $True
- echo "Account created for $fname $lname in $OUpath"
- }
- Import-Module : The specified module 'ActiveDirectory' was not loaded because no valid mod
- ule file was found in any module directory.
- At line:1 char:14
- + Import-Module <<<< ActiveDirectory
- + CategoryInfo : ResourceUnavailable: (ActiveDirectory:String) [Import-Modul
- e], FileNotFoundException
- + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.Import
- ModuleCommand
- The term 'New-ADUser' is not recognized as the name of a cmdlet, function, script file, or
- operable program. Check the spelling of the name, or if a path was included, verify that
- the path is correct and try again.
- At line:19 char:14
- + New-ADUser <<<< -Name "$fname $lname" -GivenName $fname -Surname $lname -UserPrincip
- alName "$fname.$lname" -Path $OUpath -AccountPassword $securePassword -ChangePasswordAtLog
- on $True
- + CategoryInfo : ObjectNotFound: (New-ADUser:String) [], CommandNotFoundExce
- ption
- + FullyQualifiedErrorId : CommandNotFoundException
- Account created for User1 1 in OU=Sales,OU=Admin,OU=Clients
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement