This VBScript shows how to determine the OU the local computer belongs to.
Some of IT admins want to verify that is has been deployed to the correct OU. So this script can help do that.
Step 1: You can run this VBScript sample by simply double-clicking.
The step is shown in the following figure.

When the script finishes running, it will spawn a window that displays brief information about the result.

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
Set objADSysInfo = CreateObject("ADSystemInfo")
strComputerName = objADSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputerName)
strOUName = objComputer.DistinguishedName
strOUs = Split(strOUName, ",")
strOU = Split(strOUs(1), "=")
Set WshNetwork = CreateObject("WScript.Network") ComputerName = WshNetwork.ComputerName Set objADSysInfo = CreateObject("ADSystemInfo") strComputerName = objADSysInfo.ComputerName Set objComputer = GetObject("LDAP://" & strComputerName) strOUName = objComputer.DistinguishedName strOUs = Split(strOUName, ",") strOU = Split(strOUs(1), "=")
Windows XP or higher version