Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disable and Move to a new OU

10 views
Skip to first unread message

Jason Donati

unread,
Nov 28, 2006, 10:02:31 PM11/28/06
to
Hi Guys,

1st post here, dont beat me up to much :)

I need a script that will allow me to disable a list of computers and
then move them to a new OU. I've never done any scripting so no idea
how to procede.

Essentially, i need the script to be able to read a txt file of PC names
(list.ini, list.txt, whatever) then find each computer in AD (In
whichever OU it happens to be in, disable it, then move it to a
"Disabled Computers" OU.

Any help would be greatly appreciated.

Cheers

Jase

Richard Mueller [MVP]

unread,
Dec 4, 2006, 12:21:18 AM12/4/06
to
Jason Donati wrote:

> I need a script that will allow me to disable a list of computers and
> then move them to a new OU. I've never done any scripting so no idea
> how to procede.
>
> Essentially, i need the script to be able to read a txt file of PC names
> (list.ini, list.txt, whatever) then find each computer in AD (In
> whichever OU it happens to be in, disable it, then move it to a
> "Disabled Computers" OU.

I assume your text file is a list of the NetBIOS names of computers, one
name per line. You can use the NameTranslate object to convert this (with
the NetBIOS name of the domain) to the Distinguished Name of the object. You
can use the MoveHere method of the OU object to move the computer objects
into the target OU. You pass the AdsPath of the computer object to this
method. For example:
=============
Const ForReading = 1

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify the text file of computer NetBIOS names.
strFile = "c:\Scripts\computers.txt"

' Specify the Distinguished Name of the target OU.
strOU = "ou=Disabled Computers,ou=West,dc=MyDomain,dc=com"

' Specify the NetBIOS name of the domain.
strNetBIOSDomain = "MyDomain"

' Use the NameTranslate object to convert the NT names to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""

' Open the text file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Bind to the target OU object.
Set objOU = GetObject("LDAP://" & strOU)

' Read each line of the file.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Use the Set method to specify the NT format of the object name.
' The sAMAccountName of a computer object is the NetBIOS name
' of the computer with "$" appended on the end.
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer & "$"

' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Move the computer object to the target OU.
objOU.MoveHere "LDAP://" & strComputerDN, vbNullString

End If
Loop

' Clean up.
objFile.Close
==============

For more on using NameTranslate, see this link:

http://www.rlmueller.net/NameTranslateFAQ.htm

And if it helps, I have a sample VBScript program that finds old unused
computers based on the computer account password not being changed in a
fixed number of days. The program disables these computer objects and moves
them to a target OU. The program is linked here:

http://www.rlmueller.net/MoveOldComputers.htm

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--


Jason Donati

unread,
Dec 4, 2006, 5:14:13 AM12/4/06
to
Just what I'm looking for. Thanks very much :)

Cheers

Jase

0 new messages