'==========================================================================
'
' VBScript:  AUTHOR: Ed Wilson , MS,  5/8/2006
'
' NAME: CreateOU.vbs
'ver.1.2 renamed variables, and added err object.
' COMMENT: Key concepts are listed below:
'1.This script creates an OU. IT MUST have access to Active Directory
'2.The Domain is assumed to be nwtraders.msft. You would edit your
'3.strDomain variable to add new name of new domain
'4.You would edit value of strOUname to be name of your new OU to create.
'==========================================================================
Option Explicit
On Error Resume next
Dim strProvider 'defines how will talk to Active Directory 
Dim strOU ' path to where new object will be created
Dim strDomain 'name of Domain connecting to
Dim strClass ' the class of object we are creating
Dim strOUname 'name of object are creating
Dim objDomain 'holds connection to adsi
Dim objOU 'holds handle to create method

strProvider = "LDAP://"
strOU = "" 'when supplying a value here, a trailing comma is required
strDomain = "dc=nwtraders,dc=msft"
strClass = "organizationalunit"
strOUname = "OU=mred"

Set objDomain = GetObject(strProvider & strOU & strDomain)
	WScript.echo strProvider & strOU & strDomain 'debug
Set objOU = objDomain.create(strClass, strOUname)
	WScript.echo strClass & "," & strOUname 'debug
objOU.SetInfo

If Err.number = 0 Then
	WScript.Echo(strOUname & " was created")
Else If Err.number = "-2147019886" Then
	WScript.echo strOUname & " already exists"
Else 
	WScript.echo " error on the play " & Err.Number
End If
End If
