Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

reading csv add users to AD

$
0
0

I've googled this title and I've found a lot of cool scripts, but I've not gotten it to work yet the way I want.   

I ran get-aduser 'myuser' | export-csv c:\temp\myuser.csv   I then opened up that csv file and checked out the format.   I changed my user ID and made up a new name/user, Spider Man. (I removed the SID and ObjectGUID).  I then saved my csv file and tried to read this file and add the new user Spider Man to AD.  

I have this code but it keeps telling me my syntax and/or format is wrong.  

 

Import-Module ActiveDirectory
$UserList=Import-CSV c:\temp\ad\spiderman.csv
$Domain='@acme.org'
$dot='.'
$space=' '
$PL="OU="
$DN=",DC=acme DC,DC=org"
$Password=convertto-securestring"Welcome123"-AsPlainText-Force

$userlist


ForEach($Personin$UserList) {
cls

$Name=$Person.GivenName
$Name+=$space
$Name+=$Person.Surname
$Username=$Person.Name
$Username+=$dot
$Username+=$Person.Surname
$UPN=$Username+$Domain
$OU=$PL
# $OU += $Person.Department
$OU+=$DN

$Name
$username

NEW-ADUSER-GivenName$Person-Surname$Person.Surname-NAME$Name–SamAccountName $Username+'TMP'-Enabled 1

# I've tried a few things where +TMP is.   I need to append each user with TMP since they are # all temp workers and that way we can easily identify them.  
}

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles