[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VBSCRIPT for disabling inactive computer accounts

Posted on 2012-12-26
4
Medium Priority
?
1,140 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

650 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