$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow\n<\/code><\/pre>\nThis is what my csv looks like (see pic). I was hoping to use the $username field to set the name instead of $user.Firstname.Substring.<\/p>\n
What am I doing wrong? I appreciate the help<\/p>\n
<\/p>","upvoteCount":0,"datePublished":"2018-07-09T16:39:37.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/14","author":{"@type":"Person","name":"aaronp1551","url":"https://community.spiceworks.com/u/aaronp1551"}},{"@type":"Answer","text":"
See the $ at the beginning of every cell in youtr header row? Those should not be there.<\/p>","upvoteCount":0,"datePublished":"2018-07-09T19:17:58.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/15","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"\n\n
<\/div>\n
M Boyle:<\/div>\n
\nSee the $ at the beginning of every cell in youtr header row? Those should not be there.<\/p>\n<\/blockquote>\n<\/aside>\n
yes. I didnt think that was the correct syntax, but this is what I get when I run it with the “$” deleted:<\/p>\n
1.) Ada Gz,The server is unwilling to process the request\n<\/code><\/pre>\nhere is the slightly modified that JitenSh provided and I changed to meet the environment:<\/p>\n
<#**************************BULK AD User Creation By Allenage.com*****************************#\n Update: version 1.1 added splatting\n\nJust add fisrtname, lastname in the csv and place on C:\\ as users.csv \nExample:-\n\n ******** ##### ********\n FirstName,lastName\n George,Bush\n Thomas,Edison\n Britney,Spears\n ******** ##### ********\n\n--> Here are examples of samaccountname or username comment out rest which does'nt suit your organistation and keep the required one.\n\n $SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow\n #$Sam=$User.FirstName+$User.LastName example john snow will be Johnsnow\n #$Sam=$User.FirstName example john snow will be John\n #$Sam=$User.firstName + \".\" + $User.lastName example john snow will be John.snow\n #$Sam=$user.Lastname+$user.Firstname.Substring(0,1) example john snow will be sjohn\n\n#>\nIf (!(Get-module ActiveDirectory )) {\n Import-Module ActiveDirectory\n Clear-Host\n }\n\n$Users=Import-csv c:\\users.csv\n$a=1;\n$b=1;\n$failedUsers = @()\n$successUsers = @()\n$VerbosePreference = \"Continue\"\n$ErrorActionPreference='stop'\n$LogFolder = \"$env:userprofile\\desktop\\logs\"\n\n ForEach($User in $Users)\n {\n $FirstName = $User.FirstName.substring(0,1).toupper()+$User.FirstName.substring(1).tolower()\n $LastName = $User.LastName.substring(0,1).toupper()+$User.LastName.substring(1).tolower()\n\n $FullName = $User.FirstName + \" \" + $User.LastName\n\n $SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow as username\n <#\n $Sam=$User.FirstName+$User.LastName --> example john snow will be Johnsnow\n $Sam=$User.FirstName --> example john snow will be John\n $Sam= $User.firstName + \".\" + $User.lastName --> example john snow will be John.snow\n $Sam=$user.Lastname+$user.Firstname.Substring(0,1)) --> example john snow will be sjohn\n #>\n\n $dnsroot = '@' + (Get-ADDomain).dnsroot\n\n $SAM=$sam.tolower()\n\n # To set Diffreent Passwords for each User add header Password on CSV and change 'P@ssw0rd@123' to $user.passsword\n $Password = (ConvertTo-SecureString -AsPlainText '$user.password' -Force)\n\n \n $UPN = $SAM + \"CIS.LOCAL\" # change \"$dnsroot to custom domain if you want, by default it will take from DNS ROOT\"\n\n $OU=\"CN=users, DC=Domain,DC=COM\" # Choose an Ou where users will be created # Running cmd will show all OU's Get-ADOrganizationalUnit -Filter * | Select-Object -Property DistinguishedName| Out-GridView -PassThru| Select-Object -ExpandProperty DistinguishedName\n\n $email=$Sam + \"$CIS.LOCAL\" # change \"$dnsroot to custom domain if you want, by default it will take from DNS ROOT\"\n\nTry {\n if (!(get-aduser -Filter {samaccountname -eq \"$SAM\"})){\n $Parameters = @{\n 'SamAccountName' = $Sam\n 'UserPrincipalName' = $UPN \n 'Name' = $Fullname\n 'EmailAddress' = $Email \n 'GivenName' = $FirstName \n 'Surname' = $Lastname \n 'AccountPassword' = $password \n 'ChangePasswordAtLogon' = $true # Set False if you do not want user to change password at next logon.\n 'Enabled' = $true \n 'Path' = $OU\n 'PasswordNeverExpires' = $False # Set True if Password should expire as set on GPO.\n}\n\nNew-ADUser @Parameters\n Write-Verbose \"[PASS] Created $FullName \"\n $successUsers += $FullName + \",\" +$SAM\n }\n \n}\nCatch {\n Write-Warning \"[ERROR]Can't create user [$($FullName)] : $_\"\n $failedUsers += $FullName + \",\" +$SAM + \",\" +$_\n}\n}\nif ( !(test-path $LogFolder)) {\n Write-Verbose \"Folder [$($LogFolder)] does not exist, creating\"\n new-item $LogFolder -type directory -Force \n}\n\nWrite-verbose \"Writing logs\"\n$failedUsers |ForEach-Object {\"$($b).) $($_)\"; $b++} | out-file -FilePath $LogFolder\\FailedUsers.log -Force -Verbose\n$successUsers | ForEach-Object {\"$($a).) $($_)\"; $a++} | out-file -FilePath $LogFolder\\successUsers.log -Force -Verbose\n\n$su=(Get-Content \"$LogFolder\\successUsers.log\").count\n$fu=(Get-Content \"$LogFolder\\FailedUsers.log\").count\n\nWrite-Host \"$fu Users Creation Failed and \" -NoNewline -ForegroundColor red\nWrite-Host \"$su Users Successfully Created \" -NoNewline -ForegroundColor green\nWrite-Host \"--> Launching LogsFolder have a Look and review.\" -ForegroundColor Magenta\nStart-Sleep -Seconds 5\nInvoke-Item $LogFolder\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-09T21:10:16.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/16","author":{"@type":"Person","name":"aaronp1551","url":"https://community.spiceworks.com/u/aaronp1551"}},{"@type":"Answer","text":"\nyes. I didnt think that was the correct syntax, but this is what I get when I run it with the “$” deleted:<\/p>\n
1.) Ada Gz,The server is unwilling to process the request\n<\/code><\/pre>\n<\/blockquote>\nIn the $Parameters = @{ … } code block the only parameter needed to create the user is ’ samaccountname’ (or maybe ‘name’). Comment out all the rest and try a few test users. After each one you cna add 1 more property back (uncomment) and retest.<\/p>\n
At a guess there is a missing @ in the UPN:<\/p>\n
$UPN = $SAM + \"CIS.LOCAL\"\n<\/code><\/pre>\nAlso not sure if a space in the DN stored in $OU will cause issues.<\/p>\n
edit: sure, not user<\/p>","upvoteCount":0,"datePublished":"2018-07-09T22:17:51.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/17","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"\n\n
<\/div>\n
the_owl:<\/div>\n
\nHi there, getting ready to import 250 users into a new windows domain. Last IT guy thought Domains were a bad idea…<\/p>\n
Ive researched a bit and put together a csv and a ps1 file.<\/p>\n
Does it look good? Im a novice at powershell.<\/p>\n
{\n\t#Read user data from each field in each row and assign the data to a variable as below\n\t\t\n\t$Username \t= $User.username\n\t$Password \t= $User.password\n\t$Firstname \t= $User.firstname\n\t$Lastname \t= $User.lastname\n\t$OU \t\t= $User.ou #This field refers to the OU the user account is to be created in\n$email\t\t= $User.mail\n$department \t= $User.department\n$title\t\t= $User.title\n$phone\t\t= $User.telephoneNumber\n\n\t#Check to see if the user already exists in AD\n\tif (Get-ADUser -F {SamAccountName -eq $Username})\n\t{\n\t\t #If user does exist, give a warning\n\t\t Write-Warning \"A user account with username $Username already exist in Active Directory.\"\n\t}\n\telse\n\t{\n\t\t#User does not exist then proceed to create the new user account\n\t\t\n #Account will be created in the OU provided by the $OU variable read from the CSV file\n\t\tNew-ADUser `\n -SamAccountName $Username `\n -UserPrincipalName \"[email protected] \" `\n -Name \"$Firstname $Lastname\" `\n -GivenName $Firstname `\n -Surname $Lastname `\n -Enabled $True `\n -DisplayName \"$Lastname, $Firstname\" `\n -Path $OU `\n -AccountPassword (convertto-securestring $Password -AsPlainText -Force) \n\t}\n}\n\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nCommenting them out was very helpful. thank you! Its failing on OU. here is the OU I got from attribute editor:<\/p>\n
OU=ProgramSupport,OU=CIS,DC=CIS,DC=LOCAL\n<\/code><\/pre>\nAlso Im not sure what you mean by this:<\/p>\n
Also not user if a space in the DN stored in $OU will cause issues. \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-10T14:06:34.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/18","author":{"@type":"Person","name":"aaronp1551","url":"https://community.spiceworks.com/u/aaronp1551"}},{"@type":"Answer","text":"\nCommenting them out was very helpful. thank you! Its failing on OU. here is the OU I got from attribute editor:<\/p>\n
OU=ProgramSupport,OU=CIS,DC=CIS,DC=LOCAL\n<\/code><\/pre>\nAlso Im not sure what you mean by this:<\/p>\n
Also not user if a space in the DN stored in $OU will cause issues. \n<\/code><\/pre>\n<\/blockquote>\nThat OU path looks fine.<\/p>\n
Stupid typo: sure, not user.<\/p>","upvoteCount":0,"datePublished":"2018-07-10T14:28:00.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/19","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"
Im getting close! Going to skip the OU part for now. But Im trying to add my own SAM from the csv. Ive tried commenting out all of the sections<\/p>\n
ForEach($User in $Users)\n {\n $FirstName = $User.FirstName.substring(0,1).toupper()+$User.FirstName.substring(1).tolower()\n $LastName = $User.LastName.substring(0,1).toupper()+$User.LastName.substring(1).tolower()\n\n $FullName = $User.FirstName + \" \" + $User.LastName\n\n #$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow as username\n <#\n #$Sam=$User.FirstName+$User.LastName --> example john snow will be Johnsnow\n #$Sam=$User.FirstName --> example john snow will be John\n #$Sam= $User.firstName + \".\" + $User.lastName --> example john snow will be John.snow\n #$Sam=$user.Lastname+$user.Firstname.Substring(0,1)) --> example john snow will be sjohn\n #>\n\n<\/code><\/pre>\nBut its still defaulting to first initial last name. Some users have ada.gonzalez because there was another agonzalez. How can I have it pickup the SAM from the csv?<\/p>","upvoteCount":0,"datePublished":"2018-07-10T15:47:54.000Z","url":"https://community.spiceworks.com/t/powershell-import-of-users/659940/20","author":{"@type":"Person","name":"aaronp1551","url":"https://community.spiceworks.com/u/aaronp1551"}}]}}
Hi there, getting ready to import 250 users into a new windows domain. Last IT guy thought Domains were a bad idea…
Ive researched a bit and put together a csv and a ps1 file.
Does it look good? Im a novice at powershell.
{
#Read user data from each field in each row and assign the data to a variable as below
$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou #This field refers to the OU the user account is to be created in
$email = $User.mail
$department = $User.department
$title = $User.title
$phone = $User.telephoneNumber
#Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else
{
#User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName "$Username@emeneye.ac.uk" `
-Name "$Firstname $Lastname" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-DisplayName "$Lastname, $Firstname" `
-Path $OU `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force)
}
}
3 Spice ups
Send me a PM tomorrow and I’ll take a look when I have fresh eyes!
jitensh
(JitenSh)
July 3, 2018, 1:21am
3
I’m curious as to the reasoning behind your predecessor’s belief that “domains are a bad idea”. Care to elaborate on that, if you can?
psophos
(M Boyle)
July 3, 2018, 5:32am
5
Seems reasonable from a brief skim.
You should create a new OU and create these user accounts in it using the -Path param to New-ADUser. Then if things get badly screwed up you can just bulk delete them and re-create them.
Domains are just bad m’kayy
Thanks for the replies, I have created a few OUs, just waiting to hear back from HR as to who needs to be where.
I dont know how or why you let a network get 300+ computers big without adding a domain.
Adding one user required a PC login, a print server login, a vpn login, hosted exchange login, a linux file share login, and a papercut (printer accountability) login.
job security I guess
Well I did a test run, and it put the user in the correct OU, but she came in disabled, and password must be changed.
It also skipped email, job title and dept and phone.
Any advice to bring users in with password never expires and enabled? Also what may I have missed on attributes?
thanks
psophos
(M Boyle)
July 3, 2018, 1:54pm
9
OUs are nothing to do with HR.
They are for organising AD users/groups, etc. for IT in order to apply group policies / delegation in an efficient manner.
It also skipped email, job title and dept and phone.
Where in the New-ADUser command do you reference these?
Any error messages?
Here’s a chink of Jitens code fromt he link he posted above:
$Parameters = @{
'SamAccountName' = $Sam
'UserPrincipalName' = $UPN
'Name' = $Fullname
'EmailAddress' = $Email
'GivenName' = $FirstName
'Surname' = $Lastname
'AccountPassword' = $password
'ChangePasswordAtLogon' = $true # Set False if you do not want user to change password at next logon.
'Enabled' = $true
'Path' = $OU
'PasswordNeverExpires' = $False # Set True if Password should expire as set on GPO.
}
some of the comments should be illuminating
The script also uses a technique called splatting.
1 Spice up
s31064
(s31064)
July 3, 2018, 2:45pm
10
the_owl:
Well I did a test run, and it put the user in the correct OU, but she came in disabled, and password must be changed.
It also skipped email, job title and dept and phone.
Any advice to bring users in with password never expires and enabled? Also what may I have missed on attributes?
thanks
Add these lines at the bottom of your script:
-ChangePasswordAtLogon $False
-PasswordNeverExpires $true
Personally, I would never add either of these, but your security is up to you. Even service accounts should have password expirations as a best-practice.
As far as the accounts getting created disabled, run it on one user with
-Whatif
and it’ll usually tell you what’s going on. Check the $Error[0] variable as well. I’d suggest writing it with a Try/Catch block, but you did say you were a novice and I don’t want to add any more room for scripting syntax error (but you really should learn how to use them).
s31064
(s31064)
July 3, 2018, 2:51pm
11
M Boyle:
OUs are nothing to do with HR. They are for organising AD users/groups, etc. for IT in order to apply group policies / delegation in an efficient manner.
Any error messages?
Here’s a chink of Jitens code fromt he link he posted above:
Had this page sitting open and didn’t see your more complete reply before adding my two cents.
As far as OUs and HR, although you’re technically correct, many organizations base their OUs on HR information such as location, department, security clearance, etc.
As far as OUs and HR, although you’re technically correct, many organizations base their OUs on HR information such as location, department, security clearance, etc.
THIS^
I am building OUs for Dept and Location so I can write GPOs. So OUs do have something to do with HR.
I will add those lines in there and try thank.
I dont think I have my attributes right for the script. Thanks for pointing out the code MBoyle
I tried the script from the link above:
WARNING: [ERROR]Can't create user [test G] : The server is unwilling to process the request
PS C:\Users\Administrator> if ( !(test-path $LogFolder)) {
>> Write-Verbose "Folder [$($LogFolder)] does not exist, creating"
>> new-item $LogFolder -type directory -Force
You cannot call a method on a null-valued expression.
At line:3 char:4
+ $FirstName = $User.FirstName.substring(0,1).toupper()+$User.FirstN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Hi there. Im getting this error when running the script that @JitenSh provided.
$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow
This is what my csv looks like (see pic). I was hoping to use the $username field to set the name instead of $user.Firstname.Substring.
What am I doing wrong? I appreciate the help
psophos
(M Boyle)
July 9, 2018, 7:17pm
15
See the $ at the beginning of every cell in youtr header row? Those should not be there.
yes. I didnt think that was the correct syntax, but this is what I get when I run it with the “$” deleted:
1.) Ada Gz,The server is unwilling to process the request
here is the slightly modified that JitenSh provided and I changed to meet the environment:
<#**************************BULK AD User Creation By Allenage.com*****************************#
Update: version 1.1 added splatting
Just add fisrtname, lastname in the csv and place on C:\ as users.csv
Example:-
******** ##### ********
FirstName,lastName
George,Bush
Thomas,Edison
Britney,Spears
******** ##### ********
--> Here are examples of samaccountname or username comment out rest which does'nt suit your organistation and keep the required one.
$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow
#$Sam=$User.FirstName+$User.LastName example john snow will be Johnsnow
#$Sam=$User.FirstName example john snow will be John
#$Sam=$User.firstName + "." + $User.lastName example john snow will be John.snow
#$Sam=$user.Lastname+$user.Firstname.Substring(0,1) example john snow will be sjohn
#>
If (!(Get-module ActiveDirectory )) {
Import-Module ActiveDirectory
Clear-Host
}
$Users=Import-csv c:\users.csv
$a=1;
$b=1;
$failedUsers = @()
$successUsers = @()
$VerbosePreference = "Continue"
$ErrorActionPreference='stop'
$LogFolder = "$env:userprofile\desktop\logs"
ForEach($User in $Users)
{
$FirstName = $User.FirstName.substring(0,1).toupper()+$User.FirstName.substring(1).tolower()
$LastName = $User.LastName.substring(0,1).toupper()+$User.LastName.substring(1).tolower()
$FullName = $User.FirstName + " " + $User.LastName
$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow as username
<#
$Sam=$User.FirstName+$User.LastName --> example john snow will be Johnsnow
$Sam=$User.FirstName --> example john snow will be John
$Sam= $User.firstName + "." + $User.lastName --> example john snow will be John.snow
$Sam=$user.Lastname+$user.Firstname.Substring(0,1)) --> example john snow will be sjohn
#>
$dnsroot = '@' + (Get-ADDomain).dnsroot
$SAM=$sam.tolower()
# To set Diffreent Passwords for each User add header Password on CSV and change 'P@ssw0rd@123' to $user.passsword
$Password = (ConvertTo-SecureString -AsPlainText '$user.password' -Force)
$UPN = $SAM + "CIS.LOCAL" # change "$dnsroot to custom domain if you want, by default it will take from DNS ROOT"
$OU="CN=users, DC=Domain,DC=COM" # Choose an Ou where users will be created # Running cmd will show all OU's Get-ADOrganizationalUnit -Filter * | Select-Object -Property DistinguishedName| Out-GridView -PassThru| Select-Object -ExpandProperty DistinguishedName
$email=$Sam + "$CIS.LOCAL" # change "$dnsroot to custom domain if you want, by default it will take from DNS ROOT"
Try {
if (!(get-aduser -Filter {samaccountname -eq "$SAM"})){
$Parameters = @{
'SamAccountName' = $Sam
'UserPrincipalName' = $UPN
'Name' = $Fullname
'EmailAddress' = $Email
'GivenName' = $FirstName
'Surname' = $Lastname
'AccountPassword' = $password
'ChangePasswordAtLogon' = $true # Set False if you do not want user to change password at next logon.
'Enabled' = $true
'Path' = $OU
'PasswordNeverExpires' = $False # Set True if Password should expire as set on GPO.
}
New-ADUser @Parameters
Write-Verbose "[PASS] Created $FullName "
$successUsers += $FullName + "," +$SAM
}
}
Catch {
Write-Warning "[ERROR]Can't create user [$($FullName)] : $_"
$failedUsers += $FullName + "," +$SAM + "," +$_
}
}
if ( !(test-path $LogFolder)) {
Write-Verbose "Folder [$($LogFolder)] does not exist, creating"
new-item $LogFolder -type directory -Force
}
Write-verbose "Writing logs"
$failedUsers |ForEach-Object {"$($b).) $($_)"; $b++} | out-file -FilePath $LogFolder\FailedUsers.log -Force -Verbose
$successUsers | ForEach-Object {"$($a).) $($_)"; $a++} | out-file -FilePath $LogFolder\successUsers.log -Force -Verbose
$su=(Get-Content "$LogFolder\successUsers.log").count
$fu=(Get-Content "$LogFolder\FailedUsers.log").count
Write-Host "$fu Users Creation Failed and " -NoNewline -ForegroundColor red
Write-Host "$su Users Successfully Created " -NoNewline -ForegroundColor green
Write-Host "--> Launching LogsFolder have a Look and review." -ForegroundColor Magenta
Start-Sleep -Seconds 5
Invoke-Item $LogFolder
psophos
(M Boyle)
July 9, 2018, 10:17pm
17
yes. I didnt think that was the correct syntax, but this is what I get when I run it with the “$” deleted:
1.) Ada Gz,The server is unwilling to process the request
In the $Parameters = @{ … } code block the only parameter needed to create the user is ’ samaccountname’ (or maybe ‘name’). Comment out all the rest and try a few test users. After each one you cna add 1 more property back (uncomment) and retest.
At a guess there is a missing @ in the UPN:
$UPN = $SAM + "CIS.LOCAL"
Also not sure if a space in the DN stored in $OU will cause issues.
edit: sure, not user
the_owl:
Hi there, getting ready to import 250 users into a new windows domain. Last IT guy thought Domains were a bad idea…
Ive researched a bit and put together a csv and a ps1 file.
Does it look good? Im a novice at powershell.
{
#Read user data from each field in each row and assign the data to a variable as below
$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou #This field refers to the OU the user account is to be created in
$email = $User.mail
$department = $User.department
$title = $User.title
$phone = $User.telephoneNumber
#Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else
{
#User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName "$Username@emeneye.ac.uk" `
-Name "$Firstname $Lastname" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-DisplayName "$Lastname, $Firstname" `
-Path $OU `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force)
}
}
Commenting them out was very helpful. thank you! Its failing on OU. here is the OU I got from attribute editor:
OU=ProgramSupport,OU=CIS,DC=CIS,DC=LOCAL
Also Im not sure what you mean by this:
Also not user if a space in the DN stored in $OU will cause issues.
psophos
(M Boyle)
July 10, 2018, 2:28pm
19
Commenting them out was very helpful. thank you! Its failing on OU. here is the OU I got from attribute editor:
OU=ProgramSupport,OU=CIS,DC=CIS,DC=LOCAL
Also Im not sure what you mean by this:
Also not user if a space in the DN stored in $OU will cause issues.
That OU path looks fine.
Stupid typo: sure, not user.
Im getting close! Going to skip the OU part for now. But Im trying to add my own SAM from the csv. Ive tried commenting out all of the sections
ForEach($User in $Users)
{
$FirstName = $User.FirstName.substring(0,1).toupper()+$User.FirstName.substring(1).tolower()
$LastName = $User.LastName.substring(0,1).toupper()+$User.LastName.substring(1).tolower()
$FullName = $User.FirstName + " " + $User.LastName
#$SAM = $user.FirstName.Substring(0,1) + $user.LastName #example John snow will be Jsnow as username
<#
#$Sam=$User.FirstName+$User.LastName --> example john snow will be Johnsnow
#$Sam=$User.FirstName --> example john snow will be John
#$Sam= $User.firstName + "." + $User.lastName --> example john snow will be John.snow
#$Sam=$user.Lastname+$user.Firstname.Substring(0,1)) --> example john snow will be sjohn
#>
But its still defaulting to first initial last name. Some users have ada.gonzalez because there was another agonzalez. How can I have it pickup the SAM from the csv?