nav2567
asked on
Create multiple user accounts using Powershell
I am running the below PS script to read this NEWUSERS.CSV file:
Name samaccountname ParentOU
testuser1 testuser1 ou=testou,dc=mydomain,dc=c om
testuser2 testuser2 ou=testou,dc=mydomain,dc=c om
.....
but I do not see any users being created. I do not see any error when I run the script.
Please advise. Thanks.
Import-Module ActiveDirectory
Import-Csv "C:\bin\script\addadusers\ NewUsers.c sv" | ForEach-Object {
$userPrincinpal = $_."samAccountName" + "@mydomain.com"
New-ADUser -Name $_.Name `
-Path $_."ParentOU" `
-SamAccountName $_."samAccountName" `
-UserPrincipalName $userPrincinpal `
-AccountPassword (ConvertTo-SecureString "Mypwd$12" -AsPlainText -Force) `
-ChangePasswordAtLogon $true `
-Enabled $true
Add-ADGroupMember "Domain Admins" $_."samAccountName";
}
Name samaccountname ParentOU
testuser1 testuser1 ou=testou,dc=mydomain,dc=c
testuser2 testuser2 ou=testou,dc=mydomain,dc=c
.....
but I do not see any users being created. I do not see any error when I run the script.
Please advise. Thanks.
Import-Module ActiveDirectory
Import-Csv "C:\bin\script\addadusers\
$userPrincinpal = $_."samAccountName" + "@mydomain.com"
New-ADUser -Name $_.Name `
-Path $_."ParentOU" `
-SamAccountName $_."samAccountName" `
-UserPrincipalName $userPrincinpal `
-AccountPassword (ConvertTo-SecureString "Mypwd$12" -AsPlainText -Force) `
-ChangePasswordAtLogon $true `
-Enabled $true
Add-ADGroupMember "Domain Admins" $_."samAccountName";
}
ASKER
What is your AD-Import.csv looked like?
Where ever you see $Person.something I have a column heading for this. Below would be each users details.
Example below...
Name sn country state title .....
Mike Smith Canada Ontario Accountant
etc...
Will.
Example below...
Name sn country state title .....
Mike Smith Canada Ontario Accountant
etc...
Will.
ASKER
Thanks. I need to specify the name of the login script in the user's properties.
I added the scriptpath column but it does not work.
Can you advise again? Please see screenshot.
loginscript.png
I added the scriptpath column but it does not work.
Can you advise again? Please see screenshot.
loginscript.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
Open in new window
You will need to construct your csv headings with the same as i have Outlined in the script. If you do not want all of the settings just remove the ones that do not apply.
Will.