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" } }