JMBates Posted November 9, 2012 Posted November 9, 2012 Hello all, I'm trying to create a Powershell script to automate bulk user creation as it becomes a bit of a pain with the new intake of students each year. I have found a script online and I have slightly modified it but it doesn't appear to be working in a test environment I have. This is the script: import-module activedirectory import-module grouppolicy $mydom = (get-addomain).distinguishedname $ouName = "Sales" $oudn = "OU=$ouName,$mydom" $userCount = 10 $datetime = get-date -format G $desc = "Test user created $datetime" $OU = get-ADOrganizationalUnit -Filter { name -eq $ouName } if($OU -eq $Null) {New-ADOrganizationalUnit -Name $OUName -Path $mydom} else {write-host "The OU" $ou "already exists - this is good..."} $i = 1 while ($i -le $userCount) { $uname = "User" + $i $UDdname = "Test User" + $i New-ADUser -Name $uname -SamAccountName $uname -DisplayName $UDdname -Path $oudn -Enabled $true -ChangePasswordAtLogon $true -description $desc -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -force) -PassThru $i = $i + 1 } And I am getting this error when I attempt to run the script: New-ADUser : Directory object not found At C:\Users\James\Documents\test.ps1:26 char:11 + New-ADUser <<<< -Name $uname -SamAccountName $uname -DisplayName $UDdname -Path $oudn -Enabled $t AtLogon $true -description $desc -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -f + CategoryInfo : ObjectNotFound: (CN=User10,OU=Sa...gramming,DC=com:String) [New-ADUser undException + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Comman Can anyone point in the direction as to why this isn't working? Many thanks.
Steve21 Posted November 9, 2012 Posted November 9, 2012 Is it actually creating the sales OU? Or any users? Can't scroll error very well on phone but looks like it can't find the ou. But wanted to check if it's doing anything or just bombing out at start? Steve
JMBates Posted November 10, 2012 Author Posted November 10, 2012 A part of the script is set to look for the OU I want to create users in and it comes back saying that it has been found. $OU = get-ADOrganizationalUnit -Filter { name -eq $ouName } if($OU -eq $Null) {New-ADOrganizationalUnit -Name $OUName -Path $mydom} else {write-host "The OU" $ou "already exists - this is good..."} It keeps getting stuck at this part of the script New-ADUser -Name $uname -SamAccountName $uname -DisplayName $UDdname -Path $oudn -Enabled $true -ChangePasswordAtLogon $true -description $desc -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -force) -PassThru If I remove "-Name $uname" it will prompt me to enter User names, which I'm guessing that the script isn't designed to do so (bearing in mind this script originally came from a random blog with comments that it worked).
jmcdermott Posted November 10, 2012 Posted November 10, 2012 Have you considered just using an batch script it is a lot easier than power shell, the command is: net user {username} {password} /add You can also add /fullname "firstname surname" if you want more details added. Using excel it this is very fast to create, followed by a quick copy and paste to a batch file then run it on the server, use ad to move users to the right ou, selct all of them and change the home path and profile if needed. eg. Joe blogs net user jblogs Password1 /add /fullname "Joe Blogs" If you want a copy of my excel sheet let me know.
JMBates Posted November 10, 2012 Author Posted November 10, 2012 Have you considered just using an batch script it is a lot easier than power shell, the command is: net user {username} {password} /add You can also add /fullname "firstname surname" if you want more details added. Using excel it this is very fast to create, followed by a quick copy and paste to a batch file then run it on the server, use ad to move users to the right ou, selct all of them and change the home path and profile if needed. eg. Joe blogs net user jblogs Password1 /add /fullname "Joe Blogs" If you want a copy of my excel sheet let me know. If you could upload your Excel spreadsheet so I can take a gander, that would be brilliant. Thanks
Arthur Posted November 10, 2012 Posted November 10, 2012 (edited) You may find these links useful... richardkok.wordpress.com/2011/02/14/powershell-add-student-users-to-ad-with-an-excel-file/ richardkok.wordpress.com/2011/02/16/powershell-create-homedrive-folder-with-correct-permissions-icacls-by-using-excel/ richardkok.wordpress.com/2011/02/18/powershell-generate-passwords-into-an-excel-file/ edugeek.net/forums/windows-server-2008-r2/69251-creating-multiple-accounts.html#post619866 Edit. Just remembered Arposh New User Creation Tool. Edited November 10, 2012 by Arthur 1
JMBates Posted November 11, 2012 Author Posted November 11, 2012 You may find these links useful... richardkok.wordpress.com/2011/02/14/powershell-add-student-users-to-ad-with-an-excel-file/ richardkok.wordpress.com/2011/02/16/powershell-create-homedrive-folder-with-correct-permissions-icacls-by-using-excel/ richardkok.wordpress.com/2011/02/18/powershell-generate-passwords-into-an-excel-file/ edugeek.net/forums/windows-server-2008-r2/69251-creating-multiple-accounts.html#post619866 Edit. Just remembered Arposh New User Creation Tool. Many Thanks, Arthur. I shall have a look at these links.
Duke5A Posted November 13, 2012 Posted November 13, 2012 It looks like the script is complaining that the user object doesn't exist. I use VB for this stuff and you have to create the user before you can set the password or it'll give the exact same error. Try setting the password on a separate line after the user object has been created.
ADMaster Posted November 13, 2012 Posted November 13, 2012 I have had this process fully automated, I posted my script here. Tech Blog: Add Users Script Have a look and see if it will do what you need. 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now