http://community.spiceworks.com/topic/409427-please-read-before-posting<\/a><\/p>\nUse the code button when posting code examples. Makes them easier to read.<\/p>","upvoteCount":2,"datePublished":"2015-01-21T18:16:51.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/2","author":{"@type":"Person","name":"Little-Green-Man","url":"https://community.spiceworks.com/u/Little-Green-Man"}},{"@type":"Answer","text":"
Import-module ActiveDirectory\n$data = import-csv \"C:\\Users\\me\\Documents\\PowerSHellScripts\\test1.csv\"\n\nforeach ($user in $data){\nGet-ADUser -Filter \"SamAccountName -eq '$($user.employeename)'\" | Set-ADUser -Replace @{description=\"$($user.description)\"`\n;physicalDeliveryOfficeName=\"$($user.Office)\";Telephonenumber=\"$($user.Telephonenumber)\";mail=\"$($user.emailaddress)\"`\n;streetAddress=\"$($user.street)\";l=\"$($user.city)\";st=\"$($user.state)\";postalCode=\"$($user.postalCode)\";co=\"$($user.country)\"`\n;mobile=\"$($user.mobile)\";facsimileTelephoneNumber=\"$($user.fax)\";Title=\"$($user.title)\";Department=\"$($user.department)\"`\n;Company=\"$($user.company)\";manager=\"$($user.manager)\";wWWHomePage=\"$($user.webpage)\"}\n}\n<\/code><\/pre>\n
<\/p>","upvoteCount":0,"datePublished":"2015-01-21T18:24:47.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/3","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
Import-module ActiveDirectory\n$data = import-csv \"C:\\Users\\smitchell\\Documents\\PowerSHellScripts\\test1.csv\"\nforeach ($user in $data){\n\tGet-ADUser -Filter \"SamAccountName -eq '$($user.employeename)'\" | \n\tSet-ADUser -Replace @{\n\t\tdescription=$user.description\n\t\tphysicalDeliveryOfficeName=$user.Office\n\t\tTelephonenumber=$user.Telephonenumber\n\t\tmail=$user.emailaddress\n\t\tstreetAddress=$user.street\n\t\tl=$user.city\n\t\tst=$user.state\n\t\tpostalCode=$user.postalCode\n\t\tco=$user.country\n\t\tmobile=$user.mobile\n\t\tfacsimileTelephoneNumber=$user.fax\n\t\tTitle=$user.title\n\t\tDepartment=$user.department\n\t\tCompany=$user.company\n\t\tmanager=$user.manager\n\t\twWWHomePage=$user.webpage\n\t}\n}\n\n<\/code><\/pre>\nHere is a way to lay it out that makes it easier to read and troubleshoot.<\/p>\n
As to your problem, what is the output of this; does it show all the users’ SAMs?<\/p>\n
Import-module ActiveDirectory\n$data = import-csv \"C:\\Users\\smitchell\\Documents\\PowerSHellScripts\\test1.csv\"\nforeach ($user in $data){\n\tWrite-Output $user.employeename\n}\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2015-01-21T18:28:30.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/4","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"Yes the out put lists all SAM’s in the csv list<\/p>","upvoteCount":1,"datePublished":"2015-01-21T18:31:58.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/5","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
Concerning the original script, were there any errors or warnings?<\/p>\n
Is every field in the csv, for every user, populated; any blanks?<\/p>","upvoteCount":1,"datePublished":"2015-01-21T18:36:26.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/7","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
OK, so a space behind the second SAM account name was the culprit. I was only testing with 2 rows to be safe.<\/p>\n
All set<\/p>","upvoteCount":0,"datePublished":"2015-01-21T18:43:39.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/8","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
Getting this error when i try to import.\n\n<\/code><\/pre>\nSet-ADUser : replace<\/p>\n
At line:16 char:12<\/p>\n
\n- \n
Set-ADUser <<<< -Replace @{<\/p>\n<\/li>\n
- \n
CategoryInfo : InvalidOperation: (CN=Aigul Alliso…DC=dawood,DC=cc:ADUser) [Set-ADUser], ADInvalidOperationException<\/p>\n<\/li>\n
- \n
FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser<\/p>\n<\/li>\n<\/ul>","upvoteCount":0,"datePublished":"2015-01-21T19:19:56.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/9","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
Is every field in the csv, for every user, populated; no blanks?<\/p>","upvoteCount":0,"datePublished":"2015-01-21T19:20:54.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/10","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
No, the telephone field has some users with black and the mobile field has blanks as well. Just because they do not have numbers. I will populate with something and try again.<\/p>","upvoteCount":0,"datePublished":"2015-01-21T19:24:38.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/11","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
foreach ($user in $data){\n\t$replace = @{}\n\t\n\tIf($user.description) { $replace['description']=$user.description }\n\tIf($user.Office) { $replace['physicalDeliveryOfficeName']=$user.Office }\n\t#And so on....\n\n\tGet-ADUser -Filter \"SamAccountName -eq '$($user.employeename)'\" | \n\tSet-ADUser -Replace $replace\n}\n<\/code><\/pre>\nNeed to do something like this. You can only pass -Replace things that have values.<\/p>","upvoteCount":0,"datePublished":"2015-01-21T19:27:59.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/12","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
Pretty much updating all the fields listed in CSV, would it be easier to -clear said fields and then do -add<\/p>","upvoteCount":1,"datePublished":"2015-01-21T19:30:35.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/13","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
Then you could only pass -Add fields that had values and you’d be in the same boat.<\/p>","upvoteCount":0,"datePublished":"2015-01-21T19:33:13.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/14","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
OK got it sorted out. Thanks for all your help!!!<\/p>","upvoteCount":0,"datePublished":"2015-01-21T19:39:36.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/15","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}},{"@type":"Answer","text":"
Import-module ActiveDirectory\n$data = import-csv \"C:\\Users\\smitchell\\Documents\\PowerSHellScripts\\test1.csv\"\n\n$lookup = @{\n \"description\" = \"description\"\n \"Office\" = \"physicalDeliveryOfficeName\"\n \"Telephonenumber\" = \"Telephonenumber\"\n \"emailaddress\" = \"mail\"\n \"street\" = \"streetAddress\"\n \"city\" = \"l\"\n \"state\" = \"st\"\n \"postalCode\" = \"postalCode\"\n \"country\" = \"co\"\n \"mobile\" = \"mobile\"\n \"fax\" = \"facsimileTelephoneNumber\"\n \"title\" = \"Title\"\n \"department\" = \"Department\"\n \"company\" = \"Company\"\n \"manager\" = \"manager\"\n \"webpage\" = \"wWWHomePage\"\n}\n\n$fields = $data | \nGet-Member -MemberType NoteProperty | \nSelect-Object -ExpandProperty Name | \nWhere-Object { $_ -ne \"employeename\" }\n\nForEach ($user in $data) {\n $replace = @{}\n ForEach( $field in $fields) {\n If($user.$field) {\n $replace[$lookup[$field]] = $user.$field\n }\n }\n Get-ADUser -Filter \"SamAccountName -eq '$($user.employeename)'\" |\n Set-ADUser -Replace $replace\n}\n<\/code><\/pre>\nYou could try that, but it is only lightly tested.<\/p>","upvoteCount":2,"datePublished":"2015-01-21T19:44:35.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/16","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"
Thank that worked great!<\/p>","upvoteCount":0,"datePublished":"2015-01-21T20:59:26.000Z","url":"https://community.spiceworks.com/t/ad-powershel-bulk-update/372905/17","author":{"@type":"Person","name":"steve85441","url":"https://community.spiceworks.com/u/steve85441"}}]}}