Is your server running slowly? Check with SolarWinds ipMonitor
Get a free evaluation copy of ipMonitor
Contents for Ezine 67 - DSGet
When I first saw the DS family of command I admit to showing Philistine tendencies. In particular, it seemed as though grappling with DSGet and DSQuery was like going back to the DOS era.
Gradually, little by little, I am seeing opportunities to have fun with DSGet and DSQuery. For example, if you search for a user in Active Directory, it's not easy to discover in which OU in which
that user is located. Even if you launch ADUC and Find a user, search does not immediately give any information about the name of the OU where the object is stored.
As an alternative to Active Directory's Find, you could issue this command line request, dsquery user -name smith*. The difference is that DSQuery returns the name of the OU as part of the answer.
While I now enjoy experimenting with DSGet, in my heart, I see the main role for DS family as part of a script.
DSGet is a logical extension of DSQuery. The idea is that when DSQuery returns a list of objects, DSGet can interrogate those objects for extra properties such as, office, manager or phone number. Naturally
this pre-supposes you entered the relevant information in the user's properties sheet!
My assumption is that you are comfortable with DSQuery, if this is not the case take the time to have a refresher and study last week's ezine. Now for a reminder of that old scripting chestnut - pay close attention to syntax. At the risk of
teaching grandfathers to suck eggs, what we need is a pipe symbol ( | ) to join DSQuery with DSGet. Just to be clear, you type this pipe (|) with the shift key and the key next to the Z. (Colon : would produce an
error).
Let build a solid foundation with a DSQuery (Only found on a Windows Server 2003 DC)
dsquery user domainroot -name smith* or dsquery user -name smith*
Learning Points
Note 1: You need a Windows Server 2003 machine. Perhaps you could remote desktop into such a server?
Note 2: Feel free to change smith* to one of your users. Better still, create a test account and start filling in those user properties.
Note 3: This example is just to build a foundation. Now let us move on to DSGet.
We need to interrogate the output for more information. So we use DSGet to retrieve the description.
dsquery user domainroot -name smith* or dsquery user -name smith* | dsget user -dn -desc
Learning Points
Note 1: Master the pipe command | which separates dsquery from dsget. To create |, Hold down the shift key while pressing the key next to the Z.
Note 2: Even though dsquery told the operating system it was a user object, dsget still has to invoke user in its section of the command.
Challenge: See what happens if you omit the -dn.
If you are looking for handy network utilities, try some of the free downloads at
Tools4Ever
-display Display name is different from the user's description field. If you haven't done so already, time to get a user's properties sheet and start filling in those attribute boxes.
-office Useful property
-sn This command does not work. What's the matter with -sn? I will tell you what's wrong; dsget requires -ln instead of -sn and -fn instead of givenName grrrrrrrrrrrrrrrrrr. Calm down Guy, go with the flow; think of all these useful switches.
O.K. No more moaning. DSGet is actually fun and productive. Guess what information these switches return?
-email, -tel, -mgr, -mobile
Answers: General (tab), email address, telephone number, Organization (tab), Manager, Telephones (tab), Mobile.
Now find them on the user's properties sheet.
They say the old tricks the best, so let us try exporting the DSGet output not to screen but a text file. Here we need a different type of pipe command; this time it's the greater than symbol, for
example, > filename.txt.
So, just tag on > filename.txt to your DS command. Follow up with: notepad filename.txt.
dsquery user domainroot -name smith* or dsquery user -name smith* | dsget user -fn -ln -mgr > dsget.txt
Learning Points
Note 1: To read the file type, notepad dsget.txt
Note 2: I am impressed by the column format of the output
I would like to leave you with a few more DSGet object that you can interrogate or experiment with. In addition to user, there are the following DSGet commands : Computer, also Server - meaning DC, OU, Group, even Site and Subnet.
Note. There are also two commands called partition and quota, however, in the context of DSGet, partition and quota refer to Active Directory, not disk. For example, the application partition in Active Directory. Tell the truth, it was a big disappointment that DSGet did not return the disk information, but on reflection I was
expecting the impossible. DSGet partition means Active Directory partition.
Readers Letters
I was so pleased that two people wrote in with different ideas about how to find a user's OU without scripting.
Brian pointed out that in Active Directory Users and Computers, if you View, Advanced Features, then the OU information is available on the Object tab.
Mike G wrote in with a neat use of Add Remove Columns. If you 'Find' an object in Active Directory, it is possible to adjust the
columns to display 'Published At' . (See Diagram opposite.)
As far as DSGet is concerned, I have come from Philistine to champion. Now I really enjoy the challenge of DSGet and appreciate the way it works hand in glove with DSQuery. It also reminds of that
old truism the more you know the easier it gets.
Their topics and material are ideal for getting you started with VBScript. The
videos are easy to follow and you can control the pace. Try their free demo material and then see if you want to buy the full package.
See more about VB Script Training CD.
|