Update Job Title in Active Directory using PS

Good Morning

I have got a CSV file containing over 500 users who have had job Title changes and i need to update the Job Title in Active Directory

I am currently using this Powershell Script:

Import-Module ActiveDirectory
$data = import-csv -path C:\scripts\Titlestest.csv
foreach ($user in $data){
Get-ADUser -Filter Name -eq $($user.fullname)' | Set-ADUser -Replace @{title = $($user.newtitle)}
                       
                        }
In the Titletest.csv file, there is a column which has the users full name called fullname which displays the name like so, i.e 'Bob Smith' and there is also a column with their new Job Title called 'newtitle'

Running this script displays the following error

Get-ADUser : Error parsing query: 'Name -eq Bob Smith'' Error Message: 'syntax error' at "color:#ff0000;font-face:Lucida Console;font-size:x-small;">

At line:4 char:1

+ Get-ADUser -Filter Name -eq $($user.fullname)' | Set-ADUser -Replace @{ti ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ParserError: (:) [Get-ADUser], ADFilterParsingException

    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft

   .ActiveDirectory.Management.Commands.GetADUser

There is a bob smith in AD which i use as a test user, the CSV file at present only consists of this one user

I am wondering am i missing something simple here?

Barrie

July 24th, 2015 5:36am

Hi Barrie,

Looks like your quotes are a bit messed up. The first double quote looks like a smartquote and your first single quote looks to be a backtick instead. Also looks like your quotes in Set-ADUser are smartquotes as well.

Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 7:39am

Hi Mike

Thanks for checking and responding

Are you able to elaborate on what the correct quotations should be used for this purpose, i am sure i have used quotes in the past ok along the same lines..

Many Thanks

Barrie

July 24th, 2015 7:59am

The issue isn't really that you're using quotes, it's that they're what's known as smartquotes (or bent quotes).

Here's the difference:

Regular:

"

Smartquote:

Subtle, yes?

Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 8:03am

And this


should be

'
July 24th, 2015 8:18am

Guys

Many thanks for this

Ill give it a whirl and let you know how i get on

Barrie

Free Windows Admin Tool Kit Click here and download it now
July 24th, 2015 8:25am

Cheers, let us know if you run into problems.
July 24th, 2015 8:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics