Script to determine the OU the Local Computer Belongs to (VBScript)

Introduction

This VBScript shows how to determine the OU the local computer belongs to.

Scenarios

Some of IT admins want to verify that is has been deployed to the correct OU. So this script can help do that.

Script

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. 

PowerShell
Edit|Remove
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), "="

Prerequisite

Windows XP or higher version