I have to admit that I am fairly new at powershell but am able to get around fairly well with it. We have a client of Charter High schools that has a CMS system and they dump to a TXT file all the usernames and passwords from the CMS. We then take that list and download it to each of the 12 school locations on a nightly basis. I have a script that takes and creates new accounts from this file however the part I cant seem to figure out how to do is I also want the script to update previously created accounts with any new information such as password changes etc.
The script that we use to import the information into AD is:
$School="Homestead High School"
$StudentOU="OU=Students,DC=homestead,DC=maverickshigh,DC=local"
import-module activedirectory
Import-Csv c:\irn\students.txt-header("User Account Index","First Name","Last Name","Organization","Role","User Name","Password","Email","Phone 1","Phone1 Type","Address Type","Street1","Street2","City","State","Zip","Client Code","DOB","Gender","Comments","Language","Ethnicity","Race") | where-object {$_.Organization-eq$School-and$_.Role-eq"Student"} | % {New-ADUser-GivenName$_."First Name"-SurName$_."Last Name"-DisplayName ($_."First Name"+" "+$_."Last Name" ) -Name$_."User Name"-path$StudentOU-UserPrincipalName$_."User Name"-AccountPassword (ConvertTo-SecureString$_.Password-AsPlainText-force) -ProfilePath"\\studentapps\profiles$\students.v2"-PasswordNeverExpires$True-Enabled$True}
$StudentOU="OU=Students,DC=homestead,DC=maverickshigh,DC=local"
import-module activedirectory
Import-Csv c:\irn\students.txt-header("User Account Index","First Name","Last Name","Organization","Role","User Name","Password","Email","Phone 1","Phone1 Type","Address Type","Street1","Street2","City","State","Zip","Client Code","DOB","Gender","Comments","Language","Ethnicity","Race") | where-object {$_.Organization-eq$School-and$_.Role-eq"Student"} | % {New-ADUser-GivenName$_."First Name"-SurName$_."Last Name"-DisplayName ($_."First Name"+" "+$_."Last Name" ) -Name$_."User Name"-path$StudentOU-UserPrincipalName$_."User Name"-AccountPassword (ConvertTo-SecureString$_.Password-AsPlainText-force) -ProfilePath"\\studentapps\profiles$\students.v2"-PasswordNeverExpires$True-Enabled$True}
The txt file looks like:
"User Account Index","First Name","Last Name","Organization","Role","User Name","Password","Email","Phone 1","Phone1 Type","Address Type","Street1","Street2","City","State","Zip","Client Code","DOB","Gender","Comments","Language","Ethnicity","Race",
"25050","olga"," luna","Mavericks In Education","Guardian","09898907","water5","allenluna13@yahoo.com","(305) 245-4366","Home","","","","","","","","","Unknown","","","","",
"25050","olga"," luna","Mavericks In Education","Guardian","09898907","water5","allenluna13@yahoo.com","(305) 245-4366","Home","","","","","","","","","Unknown","","","","",
This does work on creating the new accounts but when run again if there were changes it states this account already exists. I really need the script to import new items as well as update previously created items. If you could lead me in the right direction I would greatly appreciate it.
Thanks
Robbie