Is there an easy to to accomplish this?
Rob
Hi,
GUID's are stored in OctetString syntax, which is a byte array. Byte arrays
cannot be created or modified in VBScript. This could be done in VB, where
you can declare a varible as a byte array, but it would be a lot of work.
Your string would have to first be converted from what I call the display
form, to a hex string form. Then the hex string would be converted to a byte
array. You might be able to find API functions to assist you in VB.
The opposite conversion is possible in VBScript. The byte array can be
converted to a hex string, then the hex string converted to the display form
you used. Below is an example:
Set objUser = GetObject("LDAP://cn=JSmith,ou=Sales,dc=MyDomain,dc=com")
arrbytGuid = objUser.objectGuid
strHexGuid = OctetToHexStr(arrbytGuid)
Wscript.Echo "User Guid in hex string format: " & strHexGuid
strGuid = HexGuidToGuidStr(strHexGuid)
Wscript.Echo "User Guid in display format: " & strGuid
Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (byte array) to Hex string.
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function
Function HexGuidToGuidStr(strGuid)
' Function to convert Hex Guid to display form.
Dim k
HexGuidToGuidStr = ""
For k = 1 To 4
HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 9 - 2*k, 2)
Next
HexGuidToGuidStr = HexGuidToGuidStr & "-"
For k = 1 To 2
HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 13 - 2*k, 2)
Next
HexGuidToGuidStr = HexGuidToGuidStr & "-"
For k = 1 To 2
HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 17 - 2*k, 2)
Next
HexGuidToGuidStr = HexGuidToGuidStr & "-" & Mid(strGuid, 17, 4)
HexGuidToGuidStr = HexGuidToGuidStr & "-" & Mid(strGuid, 21)
End Function
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
Someone found this article on Microsoft that converts a string to an
OctetString GUID for querying AD...
http://support.microsoft.com/default.aspx?scid=kb;en-us;325648
My only issue now is trying to set the computer GUID at the time I'm
trying to create the object... For example:
Set oComputer = computerContainer.Create("computer", "CN=" &
sComputerName)
oComputer.Put "samAccountName", sComputerName + "$"
oComputer.Put "userAccountControl", lFlag
oComputer.Put = "objectGUID", ConvertStringGUIDToHexStringGUID(strGUID)
oComputer.SetInfo
Apparently, the objectGUID object doesn't support the Put method --
even at the time of creation. Any suggestions?
Rob
The value of objectGuid is set by the system and cannot be modified.
http://msdn.microsoft.com/library/en-us/adschema/adschema/a_objectguid.asp
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
<wilt...@gmail.com> wrote in message
news:1121083867.0...@z14g2000cwz.googlegroups.com...
First, the code in the kb article you linked has a small error. The line:
ConvertGUIDToOctet = octetStr
should be:
ConvertStringGUIDToHexStringGUID = octetStr
Second, the function ConvertStringGUIDToHexStringGUID returns a string, not
a byte array. That's the key. Even if AD allowed modification of the
objectGUID attribute, you would need to create a byte array - TypeName
Byte().
Finally, I mis-spoke a bit earlier. Michael Harris pointed out a way to
create byte arrays in VBScript using the ADODB.Stream object and a temporary
file in this thread:
Still, AD does not allow you to update objectGUID.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
<wilt...@gmail.com> wrote in message
news:1121083867.0...@z14g2000cwz.googlegroups.com...
If so, I can look into writing an ActiveX DLL in VB6 to call within
VBScript, passing it the string GUID for conversion?
With regards with the objectGUID, if the 'system' sets it during
creation, then isn't there some way for the user to duplicate this
operation when they're using script to create the computer object
inside of AD?
For a general overview, we have a mix of MS and Linux systems... our
techs carry around a USB keychain with a specially compiled kernel that
pulls the GUID (in string format) of a system, along with the MAC
address of the NIC and sends that to a database, along with the
machine's host name.
A Cron job is run that pulls that information and enters the MAC
address and hostname into our DHCP table and we were hoping to use
VBScript to access the database, pull the string GUID, convert it and
create the computer object in AD to prepare it for a RIS install.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
<wilt...@gmail.com> wrote in message
news:1121104406....@f14g2000cwb.googlegroups.com...
http://support.microsoft.com/kb/302467
I just had the wrong object.
Rob
I am actually new to VB Script. I have this code below. While converting the
arrOctet (Byte Array) to a HexString this code ignores the termination
character and converts it (termination character) to its Hex equivalent. As
this array can be of variable lenght (which is decided at runtime) it adds
garbage values at the end of the HexString.
Is there a way to determine the termination character in the byte array and
convert only the valid characters ignoring the rest.
Dim k
OToHStr = ""
For k = 1 To To LenB(arrOctet)
OToHStr = OToHStr & Right("0" & Hex(AscB(MidB(arrbytOctet, k, 1))), 2)
Next
Thanks for all your help.
Rals.
Your snippet is identical to code I've used for years, but the only byte
arrays I encounter are in Active Directory. I've never seen a termination
character in the array. You would need to test for the character in the
loop. For example, if the character is hex &h00 (ascii 000):
========
Dim k, strByte
OToHStr = ""
For k = 1 To To LenB(arrOctet)
strByte = Right("0" & Hex(AscB(MidB(arrbytOctet, k, 1))), 2)
If (strByte = "00") Then
Exit For
End If
OtoHStr = OToHStr & strByte
Next
========
This assumes the termination character is just that, it delimits the end and
all characters after that are ignored. You could also code to just skip the
character and process the rest.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--