?
Solved

VBSCRIPT for disabling inactive computer accounts

Posted on 2012-12-26
4
Medium Priority
?
1,097 Views
Last Modified: 2012-12-31
Hello Team,

I need a VBscript to disable the list of computers which is available in different OU. It should be like if we can have the computers name in text file & script can take the input from the file itself & can disable it.

Regards,
Biplab
0
Comment
Question by:biplabmukh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
yo_bee earned 2000 total points
ID: 38725334
That code is nice, but if you are looking to a more dynamic script you might want to try this.

On Error Next
Dim StrComp

'************************************************************************************
'Creates a Connection Object for connection to AD				
'************************************************************************************
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

'************************************************************************************
'Opens the text file for reading
'************************************************************************************
set myFSO = CreateObject("Scripting.FileSystemObject") 
set myFile = myfso.openTextFile("\\flhlaw.local\userdata\Folders\BOSCAM\Documents\Computername.txt", 1)


Do
'************************************************************************************
'Starts to read line by line													
'************************************************************************************

strComp = myfile.Readline

'************************************************************************************
'Connecting to Active Directory														
'************************************************************************************
objConnection.Provider = "ADSDSOObject"
objConnection.Open "" 

'************************************************************************************
'Get the Root DSE from a random DC													
'************************************************************************************  

Set objRootDSE = GetObject("LDAP://RootDSE")

'************************************************************************************
'Connect to the schema container on a random DC													
'************************************************************************************  

strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set StrDC = GetObject("LDAP://" & StrDNSDomain)
StrServices = Ucase(StrDC.DC)



'************************************************************************************
'Searches AD for the computer name and returns the LDAP DN
'************************************************************************************
Set objRS = objConnection.Execute("<LDAP://" & StrDNSDomain & ">;(&(&(&(objectCategory=computer)(objectClass=computer)(Name=" & strComp &"))));Name,ADsPath;SubTree")
While Not objRS.EOF

strName = objRS.Fields.Item("Name").Value
strADs = objRS.Fields.Item("ADsPath").Value


'************************************************************************************
'Connects to the Computer Object and disables it
'************************************************************************************
 set objComputer = GetObject(StrADs)

objComputer.AccountDisabled = True 
objComputer.SetInfo 
WScript.Echo("Disabled " & strComputer & " on Active Directory")

objRS.MoveNext

Wend

set objRS = Nothing
objConnection.Close
Loop Until Myfile.AtEndOfStream
MyFile.close

Open in new window

0
 

Author Comment

by:biplabmukh
ID: 38731119
Thanks for your reply, I will validate tomorrow & let you know the update. Thanks once again.
0
 

Author Comment

by:biplabmukh
ID: 38732320
I have tested the script & it is working fine. Thanks for your help.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question