dsmod user title - Value for 'Target object for this command' has incorrect format

2.5k Views Asked by At

I want to edit a large number of users' title field on Active Directory that I have listed in a CSV file.

I can get every attribute associated with a user if I run this:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%UsrFld%))" -attr * -limit 0

However, if I attempt to do the following to edit the "title" field, using this:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%promptusername%))" -attr * -limit 0| dsmod user -title Disabled User

I get the following error:

dsmod failed:Value for 'Target object for this command' has incorrect format.

Now obviously DSMOD is telling me that that it can't interpret the first half of my syntax as an object to edit. My question is, how do I edit the title field with the query I'm using?

Thanks in advance!

1

There are 1 best solutions below

0
On

The problem here is that the output from the dsquery is all of the attributes of the user object and dsmod is just expecting the userDN. Unfortunately I ran into this trying to use dsquery * with the mail field, I had dsquery just output the attr of distinguishedName but the output is without quotes.

My dsquery: dsquery * domainroot -filter "(&(objectcategory=person)(objectclass=user)([email protected]))" -attr distinguishedName -L

The output is: CN=Some Dude,OU=BitInspector,OU=Bit Makers,OU=Mfgs,DC=Contoso,DC=Com

Dsmod is expecting input with quotes like this: "CN=Some Dude,OU=BitInspector,OU=Bit Makers,OU=Mfgs,DC=Contoso,DC=Com" because the userDN has spaces in it, thus the need for quotes.

Unfortunately I never could figure out how to put quotes around the dsquery output so I ended up going to PowerShell.