Solved

VBSCRIPT for disabling inactive computer accounts

Posted on 2012-12-26
4
1,023 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
  • 2
4 Comments
 
LVL 1

Expert Comment

by:Shizzo
ID: 38724732
0
 
LVL 22

Accepted Solution

by:
yo_bee earned 500 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't Update AD Group Policy Settings 10 22
Attention Please 10 40
VB Script: Correction backup files and folders v3 11 24
AD Sites/AD Replication 11 30
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now