Guy’s Scripting Ezine 67 – DSGet

Contents for Ezine 67 – DSGet

 ♣

This Week’s Secret

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.

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive software, download a free trial of SAM (Server & Application Monitor)

This Week’s Mission is to master DSGet

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).

Example 1 Make sure DSQuery is working

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.

Example 2 Basic 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.

Guy Recommends: Tools4ever’s UMRAUMRA The User Management Resource Administrator

Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.

It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.

Example 3 – Which extra properties shall we query?

-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.

Example 4 – Change the output.

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.)

Summary – DSGet

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.