View RSS Feed

Duke5A

Getting the UUID from a running Windows machine, or a computer's AD object

Rate this Entry
by , 25th September 2012 at 05:27 PM (7847 Views)
Quote Originally Posted by Duke5A View Post
I was having issues with this too using WDS. The UUID is stored in the netbootguid property in the machine's computer object. If you were ever curious enough to want to find out what it is you can use this script:

Code:
strLDAPComp = "LDAP://CN=machinename,OU=example computers,DC=example,DC=com"

Set objComp = GetObject(strLDAPComp)

Msgbox "AD UUID:" & ConvertObjectGuidToString(objComp.netbootguid)

Function ConvertObjectGuidToString(ByVal arrRawObjectGUID)
      Dim i, strByte
      Dim arrObjectGUID(15)
      For i = 1 To LenB(arrRawObjectGUID)
            strByte = Hex(AscB(MidB(arrRawObjectGUID, i, 1)))
            If Len(strByte) = 1 Then strByte = "0" & strByte
            arrObjectGUID(i - 1) = strByte
      Next
      ConvertObjectGuidToString = Join(arrObjectGUID, "")
End Function
To get the UUID from a Windows box (replace the . in the computer name string with a netbios name to get it from a networked Windows box) that is running, you can use this script:

Code:
'http://www.tech-archive.net/Archive/Scripting/microsoft.public.scripting.vbscript/2006-07/msg00078.html
'http://araihan.wordpress.com/2010/02/19/how-to-set-computer-naming-policy-in-windows-deployment-services-wds/
'http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_21909382.html

'On Error Resume Next
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
	
For Each objItem In colItems
	Msgbox "UUID: " & objItem.UUID
Next
I can't take a whole lot of credit for these as they were pieced together from sources around the net. Only the second script had comments in it with sources (it's been a while since I've had to use these). The UUID stored in AD actually has a part of it reversed and that is what the function in the first script fixes to make it human readable.
Categories
VB Script

Comments

Trackbacks

Total Trackbacks 0
Trackback URL: