VBScript – Determine Domain and Do Something

email me

This can be used to determine a domain, in a multi-domain enterprise. If a specific domain, do something.

Option Explicit

Dim objWMISvc, ColItems, objItem, strComputerDomain

Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", ,48 )
For Each objItem in colItems
	strComputerDomain = objItem.Domain
		If objItem.PartOfDomain Then
			'DOMAIN 1
			if strComputerDomain = "DOMAIN1.com" then
				'do something here
				msgbox "Domain 1"
			'DOMAIN 2
			elseif strComputerDomain = "DOMAIN2.com" then
				'do something here
				msgbox "Domain 2"
				'do something here
				msgbox "Everyone Else"
			end if
		end if

Set objWMISvc = Nothing
Set colItems = Nothing
objItem = ""
strComputerDomain = ""