Using different OU's for an AD domain join
In phase2 of an ENGL Imaging Toolkit's build process a machine is joined to AD, if you have configured the 'Active Directory / Workgroup' options in your ENGL project.
Sometimes you need to register a device in more than one OU. This little vbscript, to be run in phase2-before, set two variables AD_REGISTRATION_OU and AD_REGISTRATION_DOMAIN. These variables then can be used as %AD_REGISTRATION_OU% and %AD_REGISTRATION_DOMAIN% in your ENGL project.
In this vbscript the default gateway of the IP adapter is being read, using WMI. Based on the default gateway the two variables are set accordingly. You can also use other adapter properties, which are described in this MSDN article about the Win32_NetworkAdapterConfiguration class.
SetADRegistrationOU()
Function SetADRegistrationOU
on error resume next
Status = Utils.AppendLog("phase2-before.vbs: " & "SetADRegistrationOU()")
Dim strDefaultGateway
Dim oDG, oDGs, WMI
strDefaultGateway = Empty
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
Set oDGs = WMI.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each oDG in oDGs
If Not IsNull(oDG.DefaultIPGateway) And Not oDG.defaultIPGateway(0) = "0.0.0.0" Then
strDefaultGateway = oDG.DefaultIPGateway(0)
Exit For
End If
Next
Status = Utils.AppendLog("phase2-before.vbs: " & " default gateway is: " & strDefaultGateway)
select case strDefaultGateway
case "10.114.0.1"
status = Utils.SetSystemEnvironmentVariable("AD_REGISTRATION_OU", "ou=workstations,ou=rovabu hq,dc=rovabu,dc=nl")
status = Utils.SetSystemEnvironmentVariable("AD_REGISTRATION_DOMAIN", "rovabunetworks.nl")
case "10.101.0.1"
status = Utils.SetSystemEnvironmentVariable("AD_REGISTRATION_OU", "ou=laptops,ou=rovabu hq,dc=rovabu,dc=nl")
status = Utils.SetSystemEnvironmentVariable("AD_REGISTRATION_DOMAIN", "rovabunetworks.nl")
case Else
status = Utils.SetSystemEnvironmentVariable("AD_REGISTRATION_OU", "ou=workstations,ou=rovabu hq,dc=rovabu,dc=nl")
status = Utils.SetSystemEnvironmentVariable("AD_REGISTRATION_DOMAIN", "rovabunetworks.nl")
end select
If Err.Number <> 0 then
MsgBox "An error occured in routine SetADRegistrationOU()"
Status = Utils.AppendLog("phase2-before.vbs: " & "SetADRegistrationOU()" & " an error occurred " & Err.Number)
Else
Status = Utils.AppendLog("phase2-before.vbs: " & "SetADRegistrationOU()" & " successfully")
End If
End Function