Showing posts with label dsquery dsget apostrophe unicode error failed directory object not found. Show all posts
Showing posts with label dsquery dsget apostrophe unicode error failed directory object not found. Show all posts

Tuesday, 24 January 2012

a little problem with DSquery & DSget

Just came across a knotty little issue with one of our domains, and it went something like this:

2nd line support engineer: Can you write me a script to give me a list of all the users whose accounts have expiry dates and whether those accounts are disabled or not

Me: no need. Just use

dsquery user -limit 0 | dsget user -samid -acctexpires -disabled

2nd line support engineer: that's only showing me users that don't have expiry dates - and i know for a fact that some of them do.

Me: (Assuming that the items wanted were simply being swamped by the vast number of accounts that didn't have an expiry date)

ok, then try this:
dsquery user -limit 0 | dsget user -samid -acctexpires -disabled | grep -v "never"


I supplied a copy of grep.exe from the gnu unix utils ports, as i couldn't make find work after two pipes for some reason
http://sourceforge.net/projects/unxutils/

2nd line support engineer: now i'm getting nothing at all

Me:
It's at this point I decide it's probably worth shadowing the engineer's TS session and having a look for myself what is going on

After deconstructing the pipe and using text files:

dsquery user -limit 0 > users.txt (Worked fine)
type users.txt | dsget user -samid (produced some results and then failed with the error:

dsget failed: Directory object not found.
type dsget /? for help.

followed by a PARTIAL list of user samid's (causing the error to scroll off-screen and making it difficult to find))

Looking at the last samid on the list, i searched for that user in users.txt - then looked at the next user in the list. Gotcha!!!!

The next user in the list had an apostrophe in his name! - very strange.... I'd have expected microsoft to sort that one out fairly quickly.

did a google - found http://www.rlmueller.net/CharactersEscaped.htm which (although suggesting that ' was a valid character) also suggested deconstructing the command using text files and manually editing the user DSNs. - not my favorite solution

With a little but of poking around in the help for the ds command, i found a couple of highly interesting switches

-uco output unicode
-uci input unicode
-uc both of the above

and so, with a few judicious switches on the initial syntax, the command ran through without errors:

Dsquery user –uc –limit 0 | dsget user –uci –samid –acctexpires –disabled | grep –v “never”

Problem solved.

Hope this can help someone else out there with a similar problem!