Keep the snickering down. Most of this is old code that I slapped together.

code:
;=====================================================================
;=== NAME: Create Computer Account in OU in Active Directory
;=== Version: 1.01
;=== Date: 07/28/2003
;=== Author: Kelly Rabourn
;===
;===
;=== This will Create a computer account in the chosen OU in
;=== Active Directory.
;===
;=== This WILL NOT create a computer account IF:
;=== The computer already exists IN Active Directory.
;=== You do not permission to add to the selected OU.
;=== The computer shows Gone.
;===
;=====================================================================
BREAK ON

;--- Variables for creating and showing information
$Width = 79
$Height = 24
$Title = "Add Computers to OU"
$Nul = SetTitle ($Title)
$HeaderMaster = "Computer" + Chr(9) + "Ping Status" + Chr(9) + "Add OU Code" +
Chr(9) + "Add OU Status" + Chr(9) + "Computer OU" + Chr(9) + "Add To OU" +
Chr(9) + "Started at " + @Date + " - " + @Time

;--- Output Files
$FileMaster = ".\Add-PC-Active Directory.txt"

;--- Input Files
$LineIn = ''
$FileComputers = ".\Computers.txt"

IF NOT Exist ($FileComputers)
EXIT 1
ENDIF

;*** CHANGE ME
$ADOU = ",OU=Workstations,DC=name,DC=company,DC=com"
$ComputerOU = ""
$ComputerOUCode = ""
$ComputerOUStatus = ""

$Title = "Select a Office Type"
$Ttitle2 = "Press the Excape key to exit."
$ChoiceKeys = "C","O"
$Choices = "CDT","(ODT)"
$SelectOfficeType = Ucase(fnPopupMenu($Title,$Ttitle2,$Choices,$ChoiceKeys,25,10))
SELECT
CASE $SelectOfficeType = "C"
$ADOU = ",OU=CorporateDesktop" + $ADOU
$Title = "Select a CDT OU"
$Ttitle2 = "Press the Excape key to exit."
$ChoiceKeys = "A","B","C","D","E","F","G","H","I","J","K","L","M"
$Choices = "Connecticut (CDT)","Illinois (CDT)","Indiana (CDT)",
"Michigan (CDT)","Ohio (CDT)","Wisconsin (CDT)","Arkansas (CDT)",
"Kansas (CDT)","Missouri (CDT)","Oklahoma (CDT)","Texas (CDT)",
"California (CDT)","Nevada (CDT)"
$SelectOU = Ucase(fnPopupMenu($Title,$Ttitle2,$Choices,$ChoiceKeys,25,6))
SELECT
CASE $SelectOU = "A"
$ADOU = "OU=CT,OU=EAST" + $ADOU
CASE $SelectOU = "B"
$ADOU = "OU=IL,OU=GREATLAKES" + $ADOU
CASE $SelectOU = "C"
$ADOU = "OU=IN,OU=GREATLAKES" + $ADOU
CASE $SelectOU = "D"
$ADOU = "OU=MI,OU=GREATLAKES" + $ADOU
CASE $SelectOU = "E"
$ADOU = "OU=OH,OU=GREATLAKES" + $ADOU
CASE $SelectOU = "F"
$ADOU = "OU=WI,OU=GREATLAKES" + $ADOU
CASE $SelectOU = "G"
$ADOU = "OU=AR,OU=MIDWEST" + $ADOU
CASE $SelectOU = "H"
$ADOU = "OU=KS,OU=MIDWEST" + $ADOU
CASE $SelectOU = "I"
$ADOU = "OU=MO,OU=MIDWEST" + $ADOU
CASE $SelectOU = "J"
$ADOU = "OU=OK,OU=MIDWEST" + $ADOU
CASE $SelectOU = "K"
$ADOU = "OU=TX,OU=MIDWEST" + $ADOU
CASE $SelectOU = "L"
$ADOU = "OU=CA,OU=WEST" + $ADOU
CASE $SelectOU = "M"
$ADOU = "OU=NV,OU=WEST" + $ADOU
ENDSELECT
CASE $SelectOfficeType = "O"
$ADOU = ",OU=OperationalDesktop" + $ADOU
$Title = "Select a ODT OU"
$Ttitle2 = "Press the Excape key to exit."
$ChoiceKeys = "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"
$Choices = "Illinois (ODT)","Indiana (ODT)","Michigan (ODT)","Ohio (ODT)",
"Wisconsin (ODT)","California (ODT)","Central West Texas (ODT)",
"Dallas (ODT)","Houston (ODT)","Kansas City (ODT)","Little Rock (ODT)",
"Oklahoma City (ODT)","San Antonio (ODT)","St Louis (ODT)","West (ODT)",
"SNET (ODT)"
$SelectOU = Ucase(fnPopupMenu($Title,$Ttitle2,$Choices,$ChoiceKeys,25,4))
SELECT
CASE $SelectOU = "A"
$ADOU = "OU=IL,OU=AIT" + $ADOU
CASE $SelectOU = "B"
$ADOU = "OU=IN,OU=AIT" + $ADOU
CASE $SelectOU = "C"
$ADOU = "OU=MI,OU=AIT" + $ADOU
CASE $SelectOU = "D"
$ADOU = "OU=OH,OU=AIT" + $ADOU
CASE $SelectOU = "E"
$ADOU = "OU=WI,OU=AIT" + $ADOU
CASE $SelectOU = "F"
$ADOU = "OU=CAL,OU=MODS" + $ADOU
CASE $SelectOU = "G"
$ADOU = "OU=CWT,OU=MODS" + $ADOU
CASE $SelectOU = "H"
$ADOU = "OU=DLS,OU=MODS" + $ADOU
CASE $SelectOU = "I"
$ADOU = "OU=HOU,OU=MODS" + $ADOU
CASE $SelectOU = "J"
$ADOU = "OU=KCY,OU=MODS" + $ADOU
CASE $SelectOU = "K"
$ADOU = "OU=LTR,OU=MODS" + $ADOU
CASE $SelectOU = "L"
$ADOU = "OU=OKC,OU=MODS" + $ADOU
CASE $SelectOU = "M"
$ADOU = "OU=SAN,OU=MODS" + $ADOU
CASE $SelectOU = "N"
$ADOU = "OU=STL,OU=MODS" + $ADOU
CASE $SelectOU = "O"
$ADOU = "OU=ODWEST" + $ADOU
CASE $SelectOU = "P"
$ADOU = "OU=SNET" + $ADOU
ENDSELECT
ENDSELECT

IF $SelectOfficeType = "" OR $SelectOU = ""
GOTO "End"
ENDIF

CLS

IF Open (1, $FileComputers) = 0
$Row = 18
GOSUB "ClearScreen"
$Computer = Trim(ReadLine (1))
DO
$Nul = fnPingQuick($Computer, 1, 1000, 32, 128)
$Result = @Error
SELECT
CASE $Result < 3
SELECT
CASE $Result = 0
$StatusPing = "On"
CASE $Result = 1
$StatusPing = "Slow"
CASE $Result = 2
$StatusPing = "Off"
ENDSELECT
$objComputer = fnADSearch($Computer,,"Computer")
FOR EACH $instComputer IN $objComputer
$ComputerOU = Split($instComputer, "AccountName")[0]
NEXT
IF $ComputerOU = ""
$ADS_UF_PASSWD_NOTREQD = &20
$ADS_UF_WORKSTATION_TRUST_ACCOUNT = &1000
$objContainer = GetObject("LDAP://" + $ADOU)
$objComputer = $objContainer.Create("Computer", "cn=" + $Computer)
$objComputer.Put ("sAMAccountName", $Computer + "$")
$objComputer.Put ("userAccountControl", $ADS_UF_PASSWD_NOTREQD)
$objComputer.Put ("userAccountControl", $ADS_UF_WORKSTATION_TRUST_ACCOUNT)
$objComputer.SetInfo
$objComputer.SetPassword (Lcase($Computer) + "$")
$ComputerOUCode = fnConvertCOMerror(@Error)
$ComputerOUStatus = @SError
ELSE
$ComputerOUCode = 9
$ComputerOUStatus = "Exists"
ENDIF
CASE $Result = 3
$StatusPing = "Gone"
ENDSELECT
$LineOut = $Computer + Chr(9) + $StatusPing + Chr(9) + $ComputerOUCode + Chr(9) +
$ComputerOUStatus + Chr(9) + $ComputerOU + Chr(9) + $ADOU
GOSUB ShowInfo
$Row = $Row - 1
$FileOut = $FileMaster
$RC = fnWriteFile($FileOut, $LineOut, $HeaderMaster)
$ComputerOU = ""
$ComputerOUCode = ""
$ComputerOUStatus = ""
$Computer = Trim(ReadLine (1))
UNTIL @Error <> 0
$RC = Close (1)
ENDIF

:End
COLOR w/n
QUIT 1

:ClearScreen
;--- This will clear the screen and show the title.
COLOR b/b
CLS
COLOR r+/b
At ($Height - $Height, ($Width - Len($Title)) / 2 )
$Title
RETURN

:ShowInfo
;--- This will show the information on the screen.
IF $Row = 1
$Row = 18
GOSUB ClearScreen
ENDIF
COLOR y+/b
At ($Height - 19, 0)
"Computer Ping Err Code Err Status Computer OU New OU"
COLOR w/b
At ($Height - $Row, 0)
$Computer
At ($Height - $Row, 17)
$StatusPing
At ($Height - $Row, 25)
$ComputerOUCode
At ($Height - $Row, 33)
Left($ComputerOUStatus, 11)
At ($Height - $Row, 45)
Left($ComputerOU, 17)
At ($Height - $Row, 63)
Left($ADOU, 16)
GOSUB "HideInfo"
RETURN

:HideInfo
;This will hide information from the screen.
COLOR b/b
$Nul = At ($Height - 22, 0)
RETURN

;================================================================
FUNCTION fnWriteFile($FileName, $LineOut, OPTIONAL $HeaderLine)
;--- This will write a line of text to a file.
IF NOT Exist ($FileName) AND $HeaderLine <> ""
$RC = Open (10, $FileName, 5)
$RC = WriteLine (10, $HeaderLine + @CRLF)
$RC = Close (10)
ENDIF
IF $LineOut <> ""
$RC = Open (10, $FileName, 5)
$RC = WriteLine (10, $Lineout + @CRLF)
$RC = Close (10)
$fnWriteFile = 0
ELSE
$fnWriteFile = 1
ENDIF
ENDFUNCTION
;================================================================
FUNCTION fnPopupQuestion($PopupPrompt, OPTIONAL $PopupSecondPrompt, $PopupX, $PopupY,
OPTIONAL $PopupUserWidth, OPTIONAL $PopupUserHeight)

DIM $PopupQuestionErr, $PopupKey, $PopupHeight, $PopupWidth
$PopupQuestionErr = 0
$fnPopupQuestion = ""
IF $PopupUserHeight = ""
IF $PopupSecondPrompt = ""
$PopupSecondPrompt = "Press the Escape key to exit."
ENDIF
$PopupHeight = 3
ELSE
$PopupHeight = $PopupUserHeight
ENDIF
IF $PopupUserWidth = ""
IF Len ($PopupPrompt) > Len ($PopupSecondPrompt)
$PopupWidth = Len ($PopupPrompt)
ELSE
$PopupWidth = Len ($PopupSecondPrompt)
ENDIF
ELSE
$PopupWidth = $PopupUserWidth
ENDIF
$PopupWidth = $PopupWidth + 2
COLOR w+/b
$Nul = Box ($PopupY, $PopupX, $PopupY + $PopupHeight, $PopupX + $PopupWidth, "single")
$Nul = At ($PopupY, $PopupX + 1)
Substr ($PopupPrompt, 1, $PopupWidth - 2)
$Nul = At ($PopupY + $PopupHeight, $PopupX + 1)
$Nul = Substr ($PopupSecondPrompt, 1, $PopupWidth - 2)
$Nul = At ($PopupY + 1, $PopupX + 1)
DO
GET $PopupKey
IF $PopupKey <> Chr (224)
SELECT
CASE $PopupKey = Chr (27)
$fnPopupQuestion = ""
$PopupQuestionErr = 1
GOTO PopupQuestionExit
CASE $PopupKey = Chr (13) AND $fnPopupQuestion = ""
$fnPopupQuestion = ""
$PopupQuestionErr = 0
GOTO PopupQuestionExit
CASE $PopupKey = Chr (8)
$fnPopupQuestion = Substr($fnPopupQuestion, 1, Len($fnPopupQuestion) - 1) + " "
At ($PopupY + 1, $PopupX + 1)
$fnPopupQuestion
$fnPopupQuestion = Substr($fnPopupQuestion, 1, Len($fnPopupQuestion) - 1)
At ($PopupY + 1, $PopupX + 1)
$fnPopupQuestion
$PopupKey = ""
CASE 1
IF $PopupKey <> Chr (13)
$fnPopupQuestion = $fnPopupQuestion + $PopupKey
ENDIF
ENDSELECT
$PopupKey
ELSE
GET $PopupKey
ENDIF
UNTIL $PopupKey = Chr (13) or $PopupKey = Chr (27) ; CR,ESC ?
:PopupQuestionExit
EXIT $PopupQuestionErr
ENDFUNCTION
;================================================================
FUNCTION fnPopupMenu($PopupPrompt, OPTIONAL $PopupSecondPrompt, $PopupItems,
OPTIONAL $PopupItemKeys, $PopupX, $PopupY)

DIM $PopupMenuError, $PopupOption, $PopupN, $PopupCurrent, $PopupPrevious
DIM $PopupKey, $PopupHeight, $PopupWidth
$PopupMenuError = 0
$fnPopupMenu = ""
IF VarTypeName($PopupItems) <> "variant[]"
$PopupMenuError = @Error
GOTO PopupMenuEnd
ENDIF
$PopupHeight = UBound ($PopupItems) + 2
$PopupWidth = Len ($PopupPrompt)
IF $PopupSecondPrompt = ""
$PopupSecondPrompt = "Press the Escape key to exit."
ENDIF
IF Len ($PopupSecondPrompt) > $PopupWidth
$PopupWidth = Len ($PopupSecondPrompt)
ENDIF
FOR EACH $PopupOption IN $PopupItems
IF Len ($PopupOption) > $PopupWidth
$PopupWidth = Len ($PopupOption)
ENDIF
NEXT

$PopupWidth = $PopupWidth + 2
COLOR w+/b
Box ($PopupY, $PopupX, $PopupY + $PopupHeight, $PopupX + $PopupWidth, "single")
At ($PopupY, $PopupX + 1)
Substr ($PopupPrompt, 1, $PopupWidth - 2)
At ($PopupY + $PopupHeight, $PopupX + 1)
Substr ($PopupSecondPrompt, 1, $PopupWidth - 2)
$PopupN = 0
$PopupOption = 0
FOR EACH $PopupOption IN $PopupItems
At ($PopupY + $PopupN + 1, $PopupX + 1)
IF VarTypeName($PopupItemKeys) = "variant[]"
COLOR w+/b
$PopupItemKeys[$PopupN]
" "
ENDIF
COLOR w/b
$PopupOption
$PopupN =$PopupN + 1
NEXT
$PopupCurrent = 0
$PopupPrevious = $PopupCurrent
COLOR b/w+
At ($PopupY + $PopupCurrent + 1, $PopupX + 1)
IF VarTypeName($PopupItemKeys) = "variant[]"
$PopupItemKeys[$PopupCurrent]
" "
ENDIF
$PopupItems[$PopupCurrent]

DO
At ($PopupY + 1, $PopupX + $PopupWidth - 1)
COLOR b/b
GET $PopupKey
FOR EACH $ItemKey IN $PopupItemKeys
IF $ItemKey = $PopupKey
$fnPopupMenu = $PopupKey
GOTO PopupMenuEnd
ENDIF
NEXT
IF $PopupKey = Chr (224) ; Extended Key
GET $PopupKey
IF $PopupKey = Chr (80) ; Down Arrow
$PopupCurrent = $PopupCurrent + 1
IF $PopupCurrent = UBound ($PopupItems) + 1
$PopupCurrent = 0
ENDIF
ENDIF
IF $PopupKey = Chr (72) ; Up Arrow
$PopupCurrent = $PopupCurrent - 1
IF $PopupCurrent = -1
$PopupCurrent = UBound ($PopupItems)
ENDIF
ENDIF
IF $PopupCurrent <> $PopupPrevious
COLOR b/w+
At ($PopupY + $PopupCurrent + 1, $PopupX + 1)
IF VarTypeName($PopupItemKeys) = "variant[]"
$PopupItemKeys[$PopupCurrent]
" "
ENDIF
$PopupItems[$PopupCurrent]

At ($PopupY + $PopupPrevious + 1, $PopupX + 1)
IF VarTypeName($PopupItemKeys) = "variant[]"
COLOR w+/b
$PopupItemKeys[$PopupPrevious]
" "
ENDIF
COLOR w/b
$PopupItems[$PopupPrevious]
ENDIF
$PopupPrevious = $PopupCurrent
ENDIF
IF $PopupKey = Chr (13)
IF VarTypeName($PopupItemKeys) = "variant[]"
$fnPopupMenu = $PopupItemKeys[$PopupCurrent]
ELSE
$fnPopupMenu = $PopupItems[$PopupCurrent]
ENDIF
ENDIF
UNTIL $PopupKey = Chr (13) OR $PopupKey = Chr (27) ; CR,ESC ?
:PopupMenuEnd
COLOR b/b
Box ($PopupY, $PopupX, $PopupY + $PopupHeight, $PopupX + $PopupWidth, "full")
COLOR w/n
EXIT $PopupMenuError
ENDFUNCTION
;================================================================
FUNCTION fnPingQuick($Address, OPTIONAL $PingCount, OPTIONAL $PingWait,
OPTIONAL $PacketSize, OPTIONAL $PingTTL)

;----------------------------------------------------------------
;--- This function will Ping an address and return an error code
;--- , an IP address and an IP host name.
;--- 0 - The address is on.
;--- 1 - The address is a slow link, such as RAS/ISDN/VPN.
;--- 2 - The address is off.
;--- 3 - The address does not exist.
;----------------------------------------------------------------
GLOBAL $IPAddress, $IPName, $IPError, $IPAvgTime, $IPLinkSpeed
DIM $WshShell, $oExec, $IPTime, $IPErrorCode, $PingLine, $Index1, $Index2
DIM $Index3, $Index4
$IPAddress = ""
$IPName = ""
$IPError = "Unknown error"
$IPErrorCode = 3
IF $PingCount = ""
$PingCount = 4
ENDIF
IF $PingWait = ""
$PingWait = 4000
ENDIF
IF $PacketSize = ""
$PacketSize = 32
ENDIF
IF $PingTTL = ""
$PingTTL = 128
ENDIF
$IPTime = ""
$WshShell = CreateObject ("WScript.Shell")
$oExec = $WshShell.Exec ("%Comspec% /e:1024 /C ping -a -n " + $PingCount +
" -w " + $PingWait + " -l " + $PacketSize + " -i " + $PingTTL + " " + $Address)
WHILE NOT $oExec.StdOut.AtEndOfStream
$PingLine = $oExec.StdOut.ReadLine
SELECT
CASE InStr ($PingLine, "Pinging ")
$IPError = "Pinging"
$Index1 = 9
IF InStr ($PingLine, "[")
IF InStr ($Address, ".")
$Index2 = InStr ($PingLine, ".")
ELSE
$Index2 = InStr ($PingLine, "[") - 1
ENDIF
$Index3 = InStr ($PingLine, "[") + 1
$Index4 = InStr ($PingLine, "]")
$IPName = Substr ($PingLine, $Index1, $Index2 - $Index1)
$IPAddress = Substr ($PingLine, $Index3, $Index4 - $Index3)
ELSE
$IPAddress = ""
$IPName = ""
ENDIF
CASE InStr ($PingLine, "TTL expired in transit")
$IPError = "TTL expired in transit"
$IPErrorCode = 2
CASE InStr ($PingLine, "TTL expired during reassembly")
$IPError = "TTL expired during reassembly"
$IPErrorCode = 2
CASE InStr ($PingLine, "Request timed out")
$IPError = "Request timed out"
$IPErrorCode = 2
CASE InStr ($PingLine, "host unreachable")
$IPError = "host unreachable"
$IPErrorCode = 2
CASE InStr ($PingLine, "net unreachable")
$IPError = "net unreachable"
$IPErrorCode = 3
CASE InStr ($PingLine, "protocol unreachable")
$IPError = "protocol unreachable"
$IPErrorCode = 3
CASE InStr ($PingLine, "port unreachable")
$IPError = "port unreachable"
$IPErrorCode = 3
CASE InStr ($PingLine, "Bad")
$IPError = "Bad"
$IPErrorCode = 3
CASE InStr ($PingLine, "Unknown host")
$IPError = "Unknown host"
$IPErrorCode = 3
CASE InStr ($PingLine, "Reply from")
$IPError = "Reply from"
$IPErrorCode = 0
ENDSELECT
$PingLine = ReadLine(10)
LOOP
$PingLineQuick = $IPError
EXIT $IPErrorCode
ENDFUNCTION
;================================================================
FUNCTION fnADSearch(OPTIONAL $ADFullName, OPTIONAL $ADAccountName, OPTIONAL $ObjectType)
DIM $AdoCon
DIM $AdoCommand
DIM $Recordset
DIM $Filter
DIM $i
SELECT
CASE Len($ADFullName) > 0 AND Len($ADAccountName) > 0
$filter = " where cn='" + $adfullname + "' and samAccountName='" + $ADAccountName + "' "
CASE Len($ADFullName) > 0
$filter = " where cn='" + $ADFullName + "' "
CASE Len($ADAccountName) > 0
$filter = " where samAccountName='" + $ADAccountName + "' "
CASE 1
; I'm sure you don't want to retreive the complete Active Directory database
RETURN
ENDSELECT
IF Len($ObjectType) > 0
$filter = $filter + "and objectCategory='" + $ObjectType + "' "
ENDIF
$AdoCon = CreateObject("ADODB.Connection")
$AdoCon.Provider = "ADsDSOObject"
; Current credentials are used, as username and password aren't specified
$AdoCon.Open("Active Directory Provider")
; Create ADO command object for the connection.
$AdoCommand = CreateObject("ADODB.Command")
$AdoCommand.ActiveConnection = $AdoCon
$AdoCommand.CommandText = "Select AdsPath, samAccountName, GroupType,
ObjectCategory from 'LDAP://" + GetObject("LDAP://rootDSE").Get("defaultNamingContext") +
"' " + $filter
; Execute the query.
$Recordset = $AdoCommand.Execute
IF @Error=0
; $Recordset is 1 based
IF $Recordset.RecordCount > 0
REDIM $fnADSearch[$recordset.RecordCount - 1]
$Recordset.movefirst
FOR $i = 0 TO $recordset.RecordCount - 1
; Here we'll parse the fields of the current record
$fnADSearch[$i] = Substr($Recordset.Fields("AdsPath").value, 8) ; To get rid of " LDAP://"
$fnADSearch[$i] = $fnADSearch[$i] + ",AccountName=" + $Recordset.Fields("samAccountName").value + ","
IF Len($Recordset.Fields("samAccountName").value) > 0
$fnADSearch[$i] = $fnADSearch[$i] + "IsContainer=0,"
ELSE
$fnADSearch[$i] = $fnADSearch[$i] + "IsContainer=1,"
ENDIF
IF Len($Recordset.Fields("Grouptype").value) > 0
$fnADSearch[$i] = $fnADSearch[$i] + "IsGroup=1"
ELSE
$fnADSearch[$i] = $fnADSearch[$i] + "IsGroup=0"
ENDIF ; Moving to the next record we have in $Recordset
$Recordset.Movenext
NEXT
ENDIF
ENDIF
ENDFUNCTION
;================================================================
FUNCTION fnConvertCOMerror($COMError)
;--- This will convert a COM error to a understandable error code.
$fnConvertCOMerror = Val ("&" + Right (DecToHex ($COMError), 4))
EXIT $fnConvertCOMerror
ENDFUNCTION
;================================================================

;$objComputer = GetObject("LDAP://CN=" + $strComputer + ",OU=TX,OU=MIDWEST,
; OU=CorporateDesktop,OU=Workstations,DC=name,DC=company,DC=com")
;$objComputer.DeleteObject(0)



[ 07. August 2003, 05:10: Message edited by: krabourn ]
_________________________
Kelly