https://community.spiceworks.com/scripts/show/3682-bulk-create-active-directory-users-powershell-with-logs-less-rows-in-csv<\/a><\/p>","upvoteCount":1,"datePublished":"2017-07-07T23:54:19.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/2","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"There are a bunch of scripts out there for that, give the search a try. If you decide to try something for yourself, feel free to post your code here ( of so please use the insert code button) and were happy to review and help you out of you’re having issues or errors<\/p>","upvoteCount":1,"datePublished":"2017-07-07T23:54:56.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
It’s definitely worth figuring out whatever problem you are having with the AD module first and fixing that.<\/p>\n
There are other ways of interacting with AD but the PS module is by far the easiest and more people on here have experience with it.<\/p>\n
What version of windows and powershell are on your system and what OS version is the DC on?<\/p>","upvoteCount":1,"datePublished":"2017-07-08T08:21:34.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/4","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"
Hi thanks for your response, I get this when I try to run the modify csv:<\/p>\n
The hash literal was incomplete. \nAt line:5 char:1<\/p>\n
Missing closing ‘}’ in statement block. \nAt line:5 char:1<\/p>\n
Thanks Neally-I submitted this request after a good couple of hours of searching for what I needed.<\/p>\n
This is what I had written up before and it was being annoying with the AD module thing:<\/p>\n
PS C:\\Users\\emeeks.HAWAIICOUNTY> Import-Module ActiveDirectory\n$inputFile = Import-CSV c:\\test.csv\n$log = “.\\Error-Log.txt”\n$date = Get-Date\nWrite-Host “Active Directory – Telephone Number Change Script”\nStart-Sleep 2\nWrite-Host “The change process is now commencing, please wait…”\nStart-Sleep 2\nFunction ChangeTelephoneNumber\n{\n“Change Process Started On: ” + $date + “) :” | Out-File $log -Append\n“————————————————-” | Out-File $log -Append\nforeach($line in $inputFile)\n{\n$sam = $line.SamAccountName\n$officephone = $line.OfficePhone\nSet-ADUser -Identity $sam -OfficePhone $officephone\nWrite-Host “Completed Telephone Number Change For: $sam”\n“Completed Telephone Number Change For: $sam” | Out-File $log -Append\n}\nStart-Sleep 2\nWrite-Host “The process is now complete, please review the log file for any errors.”\n}\nChangeTelephoneNumber\nActive Directory – Telephone Number Change Script\n\n<\/code><\/pre>\nI don’t know JACK about PS its all very new to me. With that being said-thanks again<\/p>","upvoteCount":0,"datePublished":"2017-07-10T17:06:07.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/5","author":{"@type":"Person","name":"ellemeeks","url":"https://community.spiceworks.com/u/ellemeeks"}},{"@type":"Answer","text":"
How about we break it down, a lot and you try it like so:<\/p>\n
Start-Transcript -Path \".\\Error-Log.txt\"\nImport-Module ActiveDirectory\n$inputFile = Import-CSV c:\\test.csv\n\nforeach($line in $inputFile){\n try{\n Set-ADUser -Identity $line.SamAccountName -OfficePhone $line.OfficePhone -ErrorAction Stop -Verbose\n }catch{\n Write-Warning \"Error setting phone number for $($line.samaccountname)\"\n }\n}\n\nWrite-Output \"The process is now complete, please review the log file for any errors.\"\nStop-Transcript\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2017-07-10T17:17:34.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"I agree, you’re right I should probably figure it out for the long it will make things easier I just don’t know how to do that so that’s where you guys come in, yay! I tried figuring it out but I’m honestly really lost lol. The version for the DC is 2012r2 and the PS version is v.1.0.<\/p>","upvoteCount":0,"datePublished":"2017-07-10T17:43:35.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/7","author":{"@type":"Person","name":"ellemeeks","url":"https://community.spiceworks.com/u/ellemeeks"}},{"@type":"Answer","text":"
Hi Nealy,<\/p>\n
I attempted to use that and I got this return:<\/p>\n
Start-Transcript : This host does not support transcription.\nAt line:1 char:17\n+ Start-Transcript <<<< -Path \".\\Error-Log.txt\"\n + CategoryInfo : NotImplemented: (:) [Start-Transcript], PSNotSupportedException\n + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StartTranscriptCommand\n \nImport-Csv : Cannot process argument because the value of argument \"name\" is invalid. Change the value of the \"name\" argument and run the operation again.\nAt line:3 char:24\n+ $inputFile = Import-CSV <<<< c:\\test.csv\n + CategoryInfo : InvalidArgument: (:) [Import-Csv], PSArgumentException\n + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ImportCsvCommand\n \nWARNING: Error setting phone number for \nThe process is now complete, please review the log file for any errors.\nStop-Transcript : This host does not support transcription.\nAt line:14 char:16\n+ Stop-Transcript <<<< \n + CategoryInfo : NotImplemented: (:) [Stop-Transcript], PSNotSupportedException\n + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StopTranscriptCommand\n\n<\/code><\/pre>\nI imagine I have a lot of fluff in my original that I submitted >_<<\/p>","upvoteCount":0,"datePublished":"2017-07-10T17:45:18.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/8","author":{"@type":"Person","name":"ellemeeks","url":"https://community.spiceworks.com/u/ellemeeks"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Scriptkitty:<\/div>\n
\nStart-Transcript : This host does not support transcription.<\/p>\n<\/blockquote>\n<\/aside>\n
What OS / PowerShell version are you using?<\/p>\n
$psversiontable.psversion\n\n<\/code><\/pre>\n\n\n
<\/div>\n
Scriptkitty:<\/div>\n
\nImport-Csv : Cannot process argument because the value of argument “name” is invalid. Change the value of the “name” argument and run the operation again. \n$inputFile = Import-CSV <<<< c:\\test.csv<\/p>\n<\/blockquote>\n<\/aside>\n
Well I guess the path for your import file is not “c:\\test.csv<\/strong>”, you have to change that to the actual location of the csv file.<\/p>\nSo:<\/p>\n
\nRemove the transcript stuff in the first and last line<\/li>\n Update the path for the CSV file<\/li>\n try to run it again<\/li>\n<\/ol>\nImport-Module ActiveDirectory\n#############################UPDATE THIS#####\nforeach($line in (Import-CSV **c:\\test.csv**)){\n Set-ADUser -Identity $line.SamAccountName -OfficePhone $line.OfficePhone -Verbose\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2017-07-10T17:56:39.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/9","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Actually it is in there heh, I have it in C saved as test.csv.<\/p>\n
is this what you meant by the version?<\/p>\n
<\/p>","upvoteCount":0,"datePublished":"2017-07-10T18:00:54.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/10","author":{"@type":"Person","name":"ellemeeks","url":"https://community.spiceworks.com/u/ellemeeks"}},{"@type":"Answer","text":"
Wohoo! Success! Wow all of that stuff I had written out and it only really came down to a couple of lines, lol. Thanks so much!<\/p>","upvoteCount":0,"datePublished":"2017-07-10T18:18:55.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/12","author":{"@type":"Person","name":"ellemeeks","url":"https://community.spiceworks.com/u/ellemeeks"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Scriptkitty:<\/div>\n
\nWohoo! Success! Wow all of that stuff I had written out and it only really came down to a couple of lines, lol. Thanks so much!<\/p>\n<\/blockquote>\n<\/aside>\n
Well it has no ‘logging’ now. since you know now that that basically works, now you can add more logging and such to it and go from there.<\/p>","upvoteCount":0,"datePublished":"2017-07-10T18:20:21.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/13","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
This is so much better, I don’t need the logs really now that I think about it-I’m just happy it works <\/p>\n
thanks again<\/p>","upvoteCount":0,"datePublished":"2017-07-10T18:22:57.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/14","author":{"@type":"Person","name":"ellemeeks","url":"https://community.spiceworks.com/u/ellemeeks"}},{"@type":"Answer","text":"
Glad it solved i never this post was active unless neally spiced me. )<\/p>","upvoteCount":0,"datePublished":"2017-07-10T19:02:48.000Z","url":"https://community.spiceworks.com/t/bulk-import-to-ad-from-excel-csv-file/592101/15","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}}]}}
ellemeeks
(Scriptkitty)
July 7, 2017, 11:16pm
1
Hi
I’m trying to bulk import users to AD from an Excel or CSV file. It will be to modify existing users for username, phone number, and job title. I was hoping to find something in powershell minus the AD module cause for whatever reason I can’t get it to work. Anybody have a working script I could reference from?
5 Spice ups
jitensh
(JitenSh)
July 7, 2017, 11:54pm
2
first export existing stuff
Import-Module ActiveDirectory
get-aduser -filter * -searchbase "OU=OU,DC=DC,DC=com" -properties TelephoneNumber,MobilePhone,Title,OfficePhone,mobile |select -exp samaccountname,TelephoneNumber,MobilePhone,OfficePhone,mobile,Title |export-csv c:\users.csv -nti
modify the csv make changes
$USERS = Import-CSV c:\temp\users.csv
$USERS|Foreach{
Set-ADUSer -Identity $_.samaccountname -TelephoneNumber $_.TelephoneNumber -MobilePhone $_.MobilePhone -OfficePhone $_.officephone -mobile $_.Mobile -title $_.Title -Replace @{samaccountname $_.samAccoutname}}
this is my bulk ad creator script if any
https://community.spiceworks.com/scripts/show/3682-bulk-create-active-directory-users-powershell-with-logs-less-rows-in-csv
1 Spice up
Neally
(Neally)
July 7, 2017, 11:54pm
3
There are a bunch of scripts out there for that, give the search a try. If you decide to try something for yourself, feel free to post your code here ( of so please use the insert code button) and were happy to review and help you out of you’re having issues or errors
1 Spice up
psophos
(M Boyle)
July 8, 2017, 8:21am
4
It’s definitely worth figuring out whatever problem you are having with the AD module first and fixing that.
There are other ways of interacting with AD but the PS module is by far the easiest and more people on here have experience with it.
What version of windows and powershell are on your system and what OS version is the DC on?
1 Spice up
ellemeeks
(Scriptkitty)
July 10, 2017, 5:06pm
5
Hi thanks for your response, I get this when I try to run the modify csv:
The hash literal was incomplete.
At line:5 char:1
Missing closing ‘}’ in statement block.
At line:5 char:1
Thanks Neally-I submitted this request after a good couple of hours of searching for what I needed.
This is what I had written up before and it was being annoying with the AD module thing:
PS C:\Users\emeeks.HAWAIICOUNTY> Import-Module ActiveDirectory
$inputFile = Import-CSV c:\test.csv
$log = “.\Error-Log.txt”
$date = Get-Date
Write-Host “Active Directory – Telephone Number Change Script”
Start-Sleep 2
Write-Host “The change process is now commencing, please wait…”
Start-Sleep 2
Function ChangeTelephoneNumber
{
“Change Process Started On: ” + $date + “) :” | Out-File $log -Append
“————————————————-” | Out-File $log -Append
foreach($line in $inputFile)
{
$sam = $line.SamAccountName
$officephone = $line.OfficePhone
Set-ADUser -Identity $sam -OfficePhone $officephone
Write-Host “Completed Telephone Number Change For: $sam”
“Completed Telephone Number Change For: $sam” | Out-File $log -Append
}
Start-Sleep 2
Write-Host “The process is now complete, please review the log file for any errors.”
}
ChangeTelephoneNumber
Active Directory – Telephone Number Change Script
I don’t know JACK about PS its all very new to me. With that being said-thanks again
Neally
(Neally)
July 10, 2017, 5:17pm
6
How about we break it down, a lot and you try it like so:
Start-Transcript -Path ".\Error-Log.txt"
Import-Module ActiveDirectory
$inputFile = Import-CSV c:\test.csv
foreach($line in $inputFile){
try{
Set-ADUser -Identity $line.SamAccountName -OfficePhone $line.OfficePhone -ErrorAction Stop -Verbose
}catch{
Write-Warning "Error setting phone number for $($line.samaccountname)"
}
}
Write-Output "The process is now complete, please review the log file for any errors."
Stop-Transcript
ellemeeks
(Scriptkitty)
July 10, 2017, 5:43pm
7
I agree, you’re right I should probably figure it out for the long it will make things easier I just don’t know how to do that so that’s where you guys come in, yay! I tried figuring it out but I’m honestly really lost lol. The version for the DC is 2012r2 and the PS version is v.1.0.
ellemeeks
(Scriptkitty)
July 10, 2017, 5:45pm
8
Hi Nealy,
I attempted to use that and I got this return:
Start-Transcript : This host does not support transcription.
At line:1 char:17
+ Start-Transcript <<<< -Path ".\Error-Log.txt"
+ CategoryInfo : NotImplemented: (:) [Start-Transcript], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StartTranscriptCommand
Import-Csv : Cannot process argument because the value of argument "name" is invalid. Change the value of the "name" argument and run the operation again.
At line:3 char:24
+ $inputFile = Import-CSV <<<< c:\test.csv
+ CategoryInfo : InvalidArgument: (:) [Import-Csv], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ImportCsvCommand
WARNING: Error setting phone number for
The process is now complete, please review the log file for any errors.
Stop-Transcript : This host does not support transcription.
At line:14 char:16
+ Stop-Transcript <<<<
+ CategoryInfo : NotImplemented: (:) [Stop-Transcript], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StopTranscriptCommand
I imagine I have a lot of fluff in my original that I submitted >_<
Neally
(Neally)
July 10, 2017, 5:56pm
9
What OS / PowerShell version are you using?
$psversiontable.psversion
Well I guess the path for your import file is not “c:\test.csv ”, you have to change that to the actual location of the csv file.
So:
Remove the transcript stuff in the first and last line
Update the path for the CSV file
try to run it again
Import-Module ActiveDirectory
#############################UPDATE THIS#####
foreach($line in (Import-CSV **c:\test.csv**)){
Set-ADUser -Identity $line.SamAccountName -OfficePhone $line.OfficePhone -Verbose
}
ellemeeks
(Scriptkitty)
July 10, 2017, 6:00pm
10
Actually it is in there heh, I have it in C saved as test.csv.
is this what you meant by the version?
Neally
(Neally)
July 10, 2017, 6:10pm
11
Ok, can you try again like so?
Import-Module ActiveDirectory
#############################UPDATE THIS#####
foreach($line in (Import-CSV c:\test.csv)){
Set-ADUser -Identity $line.SamAccountName -OfficePhone $line.OfficePhone -Verbose
}
Make triple sure the path is right
1 Spice up
ellemeeks
(Scriptkitty)
July 10, 2017, 6:18pm
12
Wohoo! Success! Wow all of that stuff I had written out and it only really came down to a couple of lines, lol. Thanks so much!
Neally
(Neally)
July 10, 2017, 6:20pm
13
Well it has no ‘logging’ now. since you know now that that basically works, now you can add more logging and such to it and go from there.
ellemeeks
(Scriptkitty)
July 10, 2017, 6:22pm
14
This is so much better, I don’t need the logs really now that I think about it-I’m just happy it works
thanks again
jitensh
(JitenSh)
July 10, 2017, 7:02pm
15
Glad it solved i never this post was active unless neally spiced me. )