ad_error.txt<\/a> (6.4 KB)<\/p>\nThoughts?<\/p>\n
(i can run the script and update items and deal with errors later but little extra checks until figure this out)<\/p>","upvoteCount":2,"datePublished":"2024-07-23T20:59:50.389Z","url":"https://community.spiceworks.com/t/updating-ad-properties/1098666/1","author":{"@type":"Person","name":"Phillip1661","url":"https://community.spiceworks.com/u/Phillip1661"}},{"@type":"Answer","text":"
When I have a few min I’ll dig into the code, but my first recommendation is your input file should have exactly one test user in it and you should be able to successfully run against that user before you try and mass update AD.<\/p>","upvoteCount":2,"datePublished":"2024-07-23T21:13:48.650Z","url":"https://community.spiceworks.com/t/updating-ad-properties/1098666/2","author":{"@type":"Person","name":"PatrickFarrell","url":"https://community.spiceworks.com/u/PatrickFarrell"}},{"@type":"Answer","text":"
Get-ADUser : The search filter cannot be recognized<\/p>\n
Do you have the RSAT tools installed on the machine you are running this on? \nAre you running it as a user who has AD rights?<\/p>","upvoteCount":0,"datePublished":"2024-07-23T21:56:34.951Z","url":"https://community.spiceworks.com/t/updating-ad-properties/1098666/3","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}},{"@type":"Answer","text":"
I’d try something like so:<\/p>\n
$csv = Import-Csv 'E:\\scripts\\UpdateADusers\\ADUpdate.csv'\n\nforeach($user in $csv){\n $ad = $null\n $ad = Get-ADUser -Filter \"employeeid -eq '$($user.badgeid)'\" \n\n if($ad){\n $updateUser = @{\n identity = $ad\n title = $user.jobtitle\n department = $user.homedepartmentdescription\n description = $user.jobtitle\n employeenumber = $user.associateID\n replace = @{ \n extensionAttribute1 = $user.positionid\n physicalDeliveryOfficeName = $user.ADLocation\n }\n }\n \n try{\n Set-ADUser @updateUser -ErrorAction Stop\n }\n catch{\n $Error[0].Exception.Message\n }\n }\n\n}\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2024-07-24T06:45:45.797Z","url":"https://community.spiceworks.com/t/updating-ad-properties/1098666/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Neally is spot on. Import your CSV as a variable, then loop through that and then you should be able to use the $_ for your columns.<\/p>","upvoteCount":0,"datePublished":"2024-07-24T17:22:57.988Z","url":"https://community.spiceworks.com/t/updating-ad-properties/1098666/5","author":{"@type":"Person","name":"tb33t","url":"https://community.spiceworks.com/u/tb33t"}}]}}
Am getting error(s) when running powershell script to update AD user attributes.
Little strange I never got errors unless if could not find user, but now it seems to cycling though a few times creating a log file with over 2 errors logged.
Script used to update user attributes
Import-Csv 'E:\scripts\UpdateADusers\ADUpdate.csv' |
ForEach-Object {Get-ADUser -Filter "employeeid -eq `"$($_.badgeid)`"" |`
Set-ADUser -replace @{
extensionAttribute1 = $_.positionid
title = $_.jobtitle
department = $_.homedepartmentdescription
description = $_.jobtitle
physicalDeliveryOfficeName = $_.ADLocation
employeenumber = $_.associateID
}
}
Nothing to nutty
Csv layout
column-A=badgeID
column-B=posutionID
column-C=assicuateID
column-D=jobtitle
column-E=homedepartmentdescription
column-F=ADLocation
Currently only 1 user’s data listed for extra testing. Even though it errors out on output it still updates the AD user details.
Here is error log - I stopped it from running just a few seconds created 500 lines (using notepad++)
ad_error.txt (6.4 KB)
Thoughts?
(i can run the script and update items and deal with errors later but little extra checks until figure this out)
2 Spice ups
When I have a few min I’ll dig into the code, but my first recommendation is your input file should have exactly one test user in it and you should be able to successfully run against that user before you try and mass update AD.
2 Spice ups
Rod-IT
(Rod-IT)
July 23, 2024, 9:56pm
3
Get-ADUser : The search filter cannot be recognized
Do you have the RSAT tools installed on the machine you are running this on?
Are you running it as a user who has AD rights?
Neally
(Neally)
July 24, 2024, 6:45am
4
I’d try something like so:
$csv = Import-Csv 'E:\scripts\UpdateADusers\ADUpdate.csv'
foreach($user in $csv){
$ad = $null
$ad = Get-ADUser -Filter "employeeid -eq '$($user.badgeid)'"
if($ad){
$updateUser = @{
identity = $ad
title = $user.jobtitle
department = $user.homedepartmentdescription
description = $user.jobtitle
employeenumber = $user.associateID
replace = @{
extensionAttribute1 = $user.positionid
physicalDeliveryOfficeName = $user.ADLocation
}
}
try{
Set-ADUser @updateUser -ErrorAction Stop
}
catch{
$Error[0].Exception.Message
}
}
}
4 Spice ups
tb33t
(TB33T)
July 24, 2024, 5:22pm
5
Neally is spot on. Import your CSV as a variable, then loop through that and then you should be able to use the $_ for your columns.