dsquery | dsmod
-
Tuesday, October 25, 2011 8:32 AM
We have a case wich is as follows:
For some reason, our predecessors have entered phone numbers as 4711223344, where 47 is the current country code and 11223344 is an example phone number. However, this renders the adressbook function on mobile units useless, as this format is not supported, so one can't directly call a number. Anyway, what we need to do is add a + or 00 in front of 4711223344 so all users phone number attribs read 004711223344.
Is it then possible to use dsquery user "- all users in an OU" and | the result to dsmod user in such a way that the phone or mobile number attribute gets 00 added to the front of it?
Concrete examples are greatly appreciated.
All Replies
-
Tuesday, October 25, 2011 8:50 AM
This is not possible using it directly from DSQUERY and DSMOD
You need to get all necessary data into text file first and then import it to user objects again
This may look like
dsquery user "OULocation,dc=domain,dc=local" -name * -limit 0 | dsget user -samid -tel >>c:\users-tel.txt
edit text file and remove the first and the last line, save file. Now, run in command-line this syntax
for /f "tokens=1,2" %i in (c:\users-tel.txt) do dsquery user -samid %i | dsmod user -tel "00 %j"
That should do that trick. I hope it helps.
Regards, Krzysztof ---- Visit my blog at http://kpytko.wordpress.com- Proposed As Answer by Tanmoy Manik Tuesday, October 25, 2011 9:41 AM
- Marked As Answer by i686 Tuesday, October 25, 2011 11:05 AM
-
Tuesday, October 25, 2011 9:12 AM
Ok, so what you are saying is that is not possible in this particular scenario, because we need to add something to an attribute instead of replacing it, or in general?
Because e.g. dsquery user | dsmod user -attrib "value" is certainly possible, but then one would replace the entire attribute value.
I will test your solution, looks like it will do the trick. Thanks.
- Edited by i686 Tuesday, October 25, 2011 9:13 AM
-
Tuesday, October 25, 2011 9:21 AMNo, it's not as general rule. This is only not possible to add something to existing attribute(s). You can simply use DSQUERY | DSMOD to modify attributes (overwritting it/them) with no problem with that syntax directly.
Regards, Krzysztof ---- Visit my blog at http://kpytko.wordpress.com -
Tuesday, October 25, 2011 12:47 PM
Updated command i used in a batch file:
FOR /F "delims=, tokens=1,2" %%A in (add-tel.txt) do dsquery user -samid %%A "OU=Users,OU=Blabla,DC=domain,DC=lan" -limit 0 | dsmod user -tel "%%B"
- Marked As Answer by i686 Tuesday, October 25, 2011 12:47 PM

