Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell - Bulk-New-ADUser Creation via a csv file

$
0
0

This script creates bulk AD users via a csv file. The script creates & configures the user accounts correctly even though the following error message appears. How can I correct this?

Set-Locaiton : Cannot find path 'AD:Mydomain,OU=MyDomain,DC=My,DC=Domain,DC=org' because it does not exist.

Import-Module ActiveDirectory
$csv = Import-CSV -Path "C:\Temp\CreateUsers.csv"
cd AD:
set-location -path "OU=MyDomain,DC=My,DC=Domain,DC=org" -PassThru

foreach($Item in $csv){
    
            $newUserID=@{
            Name=$item.userID
            Description=$item.description
            GivenName=$item.UserID
            surName=$item.UserID
            DisplayName=$item.UserID
            UserPrincipalName=$item.UserID + "@MyDomain.org"
            EmployeeID=$item.Owner
            ScriptPath="login.cmd"
               }
        Try{
            New-ADUser @newUserID -ErrorAction Stop  -AccountPassword (ConvertTo-SecureString $Item.Password -AsPlainText -Force) -PassThru
            Enable-ADAccount -Identity $item.userID
            Set-ADUser -Identity $item.userID -ChangePasswordAtLogon $true 
            Write-Host "UserID $($item.UserID) created!" -ForegroundColor green
           }
        Catch{
            Write-Host "There was a problem creating UserID $($item.UserID). The account was not created!" -ForegroundColor Red
            set-location -path "c:\temp"
        }
    }



mamadukes


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>