×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBScript FAQ

Scripting for the Enterprise

Adding Right Click in ADUC To Get LDAP Path by markdmac
Posted: 7 Apr 07 (Edited 13 Jun 12)

markdmac's Enterprise Ready Scripts

By Mark D. MacLachlan, The Spiders Parlor
http://www.thespidersparlor.com/vbscript



I came up with a simple but very useful script that I thought others might like. Though the code is extemely simple, this is one of those scripts that I consider to have a large WOW factor.

Often when scripting something I will need to grab an LDAP path, I typically use ADSIEdit, but navigating ADSIEdit, and then grabbing an LDAP path can be time consuming.

The following script should be placed on each DC in the same location. Add it to the display specifiers list. It will give you the ability to right click an OU, computer, user or group object etc and be prompted with the LDAP path of the object and allow you to use Ctrl + C to copy it to the clipboard.

Here is the code:

CODE --> Specifiers

On Error Resume Next
strDN = Wscript.Arguments(0)
InputBox vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
vbCrLf & "Use Ctrl + C to copy","LDAP Path", strDN

For the purposes of this example, save the above code in a vbs file with the following name:
C:\EnterpriseScripts\ShowLDAP.vbs

To add the code to the display specifiers:
1. Open ADSIEdit.
2. Connect to the Configuration database.
3. Expand CN=DisplaySpecifiers
4. Double click CN=409
5. Edit the properties of the following:
ò CN=computer-Display
ò CN=group-Display
ò CN=organizationalUnit-Display
ò CN=user-Display

6. To each of the above add the following line under AdminContextMenu

CODE --> AdminContextMenu

2,Show LDAP,"C:\EnterpriseScripts\ShowLDAP.vbs"

Note that the path must match where you saved the script locally. The number indicates the position in the right click menu. The text after the first comma is what will be displayed in the right click menu.

7. Close the MMC. Open ADUC and right click a computer, user, group or OU and you can choose to Show LDAP.

You must close all MMC consoles in order for the new Display Specifier to show up in the list.

I've found a lot of people are confused by the steps required to modify the display specifiers, so I have scripted a solution. Copy the below code to a text file, name it AddDisplaySpecifiers.vbs and double click it to execute.

CODE --> AddDisplaySpecifiers.vbs


'==========================================================================
'
' NAME: AddDisplaySpecifier.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE : 5/14/2009
' COPYRIGHT ¬ 2009, All Rights Reserved
'
' COMMENT: Adds right menu choices to ADUC.
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
' OF THIS CODE OR INFORMATION.
'
'==========================================================================

Const ADS_PROPERTY_APPEND = 3

'Modify the Command code below (step 6 from manual instructions)

CommandCode = "3,ShowLDAP," & Chr(34)& "C:\EnterpriseScripts\ShowLDAP.vbs" & Chr(34)

Dim arrClass()
intIndex = 0

'Comment out whichever object types you don't want to be included

BuildClassArray("CN=computer-Display")
BuildClassArray("CN=contact-Display")
BuildClassArray("CN=container-Display")
BuildClassArray("CN=group-Display")
BuildClassArray("CN=publicFolder-Display")
BuildClassArray("CN=server-Display")
BuildClassArray("CN=user-Display")
BuildClassArray("CN=organizationalUnit-Display")


'Build our array of classes

Function BuildClassArray(objClass)
ReDim Preserve arrClass(intIndex)
intIndex = intIndex + 1
arrClass(UBound(arrClass)) = CStr(objClass)
End Function

'Enumerate the classes and add the display specifier

For Each oType In arrClass
Call AddDisplaySpecifier(oType,CommandCode)
Next

'Check for errors and report back

If Err.Number= 0 Then
WScript.Echo "Script completed successfully!"
Else
WScript.Echo "Sorry something went wrong. Verify AD is accessible." & _
vbCrLf & "Error: " & Err.Number & " Error Description: " & Err.Description
End If

'Worker function that adds to the adminContextMenu

Function AddDisplaySpecifier(ByVal oType, CommandCode)

Set oRootDSE = GetObject("LDAP://rootDSE")
strForestRoot = oRootDSE.Get("DefaultNamingContext")

strDN = oType & ",CN=409,CN=DisplaySpecifiers," & _
"CN=Configuration," & strForestRoot
Set objObject = GetObject("LDAP://" & strDN)
objObject.PutEx ADS_PROPERTY_APPEND, "adminContextMenu", Array(CommandCode)
objObject.setInfo
End Function

Modifications to the AddDisplaySpecifiers Script:


Edit the CommandCode line to switch the display and script names.
Example:

CODE

CommandCode = "3,ShowLDAP," & Chr(34)& "C:\ShowLDAP.vbs" & Chr(34)
A B C

A = Position in Right Click menu
B = Text to display in Right Click menu
C = Script to execute


You can specify which object types to target by commenting out (') an object class line
Example:

CODE


'Comment out whichever class you don't want to be included

BuildClassArray("CN=computer-Display")
BuildClassArray("CN=contact-Display")
BuildClassArray("CN=container-Display")
BuildClassArray("CN=group-Display")
'BuildClassArray("CN=publicFolder-Display")
BuildClassArray("CN=server-Display")
BuildClassArray("CN=user-Display")
BuildClassArray("CN=organizationalUnit-Display")

In the above example Public Folders will not get the new menu choice.

I strive for nothing less than 10s. Before you vote, if you don't think this FAQ rates a 10 please provide feedback to me first. Also please check out my other FAQs in this same forum.

Happy Scripting
Mark D. MacLachlan

Back to VBScript FAQ Index
Back to VBScript Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close