Re: Retrieving an object's GUID as a string from Active Directory

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Your script is using the .objectGUID property, but the example I posted uses the
..GUID property. Also, your script is using "SET =" but that's not necessary
because "The IADs interface converts the GUID from an octet string, as stored on
a directory server, into a string format":
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/iads_property_methods.asp


This is the example script, slightly modified for VBScript. It works for me,
using both global security groups and user accounts:


(Watch for line wraps)

Dim sADsPathObject
Dim sObjectGUID
Dim sBindByGuidStr

Dim IADsObject
Dim IADsObject2
On Error Resume Next

' Query the user for an ADsPath to start.
sADsPathObject = InputBox("This code binds to a directory object by ADsPath,
retrieves the GUID, then rebinds by GUID." & vbCrLf & vbCrLf & "Specify the
ADsPath of the object to bind to :")

If sADsPathObject = "" Then
WScript.Quit
End If

MsgBox "Binding to " & sADsPathObject

' Bind to initial object.
Set IADsObject = GetObject(sADsPathObject)

If (Err.Number <> 0) Then
MsgBox Err.Number & " on GetObject method"
WScript.Quit
End If

' Save the GUID of the object.
sObjectGUID = IADsObject.Guid

MsgBox "The GUID for " & vbCrLf & vbCrLf & sADsPathObject & vbCrLf & vbCrLf & "
is " & vbCrLf & vbCrLf & sObjectGUID

' Release the initial object.
Set IADsObject = Nothing

' Build a string for Binding to the object by GUID.
sBindByGuidStr = "LDAP://<GUID=" & sObjectGUID & ">"

MsgBox sBindByGuidStr

' Bind BACK to the Same object using the GUID.
Set IADsObject = GetObject(sBindByGuidStr)

If (Err.Number <> 0) Then
MsgBox Err.Number & " on GetObject method "
WScript.Quit
End If

MsgBox "Successfully RE bound to " & sADsPathObject & vbCrLf & vbCrLf & " using
the path:" & vbCrLf & vbCrLf & sBindByGuidStr




"Mr K" <MrK@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A37F76B2-7199-4EE7-8828-201CB5D2286E@xxxxxxxxxxxxxxxx
> The page you supplied has a VB example but the problem is that things do not
> seem so straight forward with VBScript.
>
> If I run the following script the output is a bunch of question marks...
>
> ADGroup = InputBox("I.E. F00-SQLSERVERENTMGR-2000", "Please enter Active
> Directory group", "F00-SQLSERVERENTMGR-2000")
>
> Set objGroup = GetObject("LDAP://CN="; & ADGroup & ",OU=Applications,OU=Users
> and Groups,DC=f00bar,DC=f00")
>
> WScript.Echo objGroup.objectGUID
> Set GUID = objGroup.objectGUID


.



Relevant Pages

  • Re: Prestaging RIS - produces wrong GUID
    ... retrieves the GUID it forced me to try pasting in the GUID - so I ... So I have forced the read script to use the MAC address as the source ... > ore refer to this article for the step by step if you are using ADSI to ... >> But if you look at the computer account properties on the RIS tab it says ...
    (microsoft.public.windows.server.active_directory)
  • Re: Batch Script to parse lines in text file
    ... comfortable in batch try this hybrid script ... ... My ultimate goal is to query a registry key, which lists GUID values ... echo %frienlyname% %version% ... This works fine collecting the first GUID value in this group, ...
    (microsoft.public.windows.server.scripting)
  • Re: Batch Script to parse lines in text file
    ... comfortable in batch try this hybrid script ... ... My ultimate goal is to query a registry key, ... This works fine collecting the first GUID value in this group, ... temp file and then loop thru this file, ...
    (microsoft.public.windows.server.scripting)
  • Re: Call to guid property of Scriptlet.TypeLib times out
    ... I could see the GUID. ... It still would be nice to have this working with script blocking activated. ... > I use following code in an ASP page to generate a GUID: ... > It worked fine on my WIN2000 computer running IIS. ...
    (microsoft.public.inetserver.asp.general)
  • Re: Prestaging Script...
    ... Versuche mal bei mir Bios oder GUID zu aendern. ... Poste zu Deinen RIS-Server oder MS Excel Nutten. ... > ich suche ein Script für das Prestaging von Computeraccounts im ... > Es gibt zwar ein Script von Microsoft, ...
    (microsoft.public.de.german.scripting.wsh)