So I have a csv file with following headings: jobtitle, location, DisplayName, emailaddress

I appreciate to update the AD fields of the user I need the samaccount name; so this is the script that I am using; however it is not updating the “Job Title” field in AD of any of the users

$list = Import-CSV “C:\jpl\User_info2.csv”
ForEach($user in $list)
{
$dn = $user.displayname
Get-ADUser -Filter {displayName -like $dn } | Select -ExpandProperty samaccountname |Out-File c:\users.txt -Append
}
$users= gc c:\users.txt
Foreach ($u in $users)

{
set-aduser $u -jobtitle $User.Title -verbose
}

Any help would be greatly appreciated, I am guessing I have the job title attribute wrong?

Many thanks in anticipation of anyone’s help

3 Spice ups

have you tried “set-aduser $u -title $User.Title -verbose” the field is title not jobtitle

First, please use the insert code button and select Powershell when posting PS code. Second, you say you have a header called jobtitle, yet you’re trying to set it using a header called title. You’re also calling the property jobtitle instead of title. Just a small change:

$list = Import-CSV "C:\jpl\User_info2.csv"
ForEach($user in $list)
{   
$dn = $user.displayname
Get-ADUser -Filter {displayName -like $dn } | Select -ExpandProperty samaccountname |Out-File c:\users.txt -Append
}
$users= gc c:\users.txt
Foreach ($u in $users)

{
    set-aduser $u -title $User.Jobtitle -verbose
}
2 Spice ups

following headings: jobtitle, location, DisplayName, emailaddress then choose

$User.Jobtitle 
#for others 

$User.location 

$User.emailaddress

Hi thanks for that, and although that appears to import the details it has imported the same job title for all the users, and not their actual job titles…

Help greatly appreciated

What it appears to be doing is just taking the last entry from the “title” field from my Csv file and then populating the Jobtitle field in AD with the same entry

:frowning:

Why do you need it to make a list of samAccountNames? Can you just to it in one go?

$list = Import-CSV "C:\jpl\User_info2.csv"
ForEach($user in $list)
{   
$dn = $user.displayname
Get-ADUser -Filter {displayName -like $dn } | Set-ADUser -title $User.Jobtitle -verbose
}

I assumed to import it the samaccount had to be used rather than the CN

Perfect Big Green Man - worked a treat - thanks very much, am so glad it worked as I am certain our CEO wouldn’t have appreciated his job title being Eng support trainee :slight_smile: :slight_smile:

1 Spice up

Get-ADUser will grab samaccountname, and it gets piped. No issues there. :slight_smile:

Glad it worked out for you! Be sure to mark HP/BA!