'====================================================================
'= Disable Users VBScript sample - Copyright © 2007, Dave Moats
'=
'= This sample is provided 'as-is', without any express or implied warranty.
'= In no event will the authors be held liable for any damages arising from
'= the use of this sample code.
'=
'= Permission is granted to anyone to use this sample code for any purpose,
'= including commercial applications, subject to the following restrictions:
'=
'= The origin of this code must not be misrepresented;
'= you must not claim that you wrote the original code.
'= If you use this code, an acknowledgment in the
'= documentation is requested - shown below:
'=
'= Portions Copyright © 2007, Dave Moats (http://www.davemoats.com/).
'=
'====================================================================
'====================================================================
'==
'== disableUsers.vbs - script to disable all the users in the file
'== that is provided
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")
'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
wscript.echo ( "Usage: disableUsers.vbs <Domain> <Path to Input File> <Path to Ouput file>")
dom = inputbox ( "Enter the domain where you want to disable these accounts")
inPath = inputbox ( "Enter the path to the file that contains the users you want to disable:")
outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
wscript.echo ( "Usage: disableUsers.vbs <Domain> <Path to Input File> <Path to Ouput file>")
wscript.quit ( )
else
dom = wscript.arguments.item ( 0)
inPath = wscript.arguments.item ( 1)
outPath = wscript.arguments.item ( 2)
end if
'====================================================================
'== make sure we have the info
'====================================================================
if dom = "" or inPath = "" or outPath = "" then
wscript.echo ( "There were not enough arguments passed to the script")
wscript.echo ( "Usage: disableUsers.vbs <Domain> <Path to Input File> <Path to Ouput file>")
wscript.quit ( )
end if
set inputFile = fso.opentextfile ( inPath )
set outputFile = fso.createtextfile ( outPath )
strComment = "Acct disabled on " & date
'====================================================================
'== turn off the wscript error handling - so this script can trap
'== any errors
'====================================================================
on error resume next
'====================================================================
'== loop thru the input file and process the contents
'====================================================================
do while not ( inputFile.atendofstream)
'==================================================================
'== bind to the user specified in the file
'==================================================================
inLine = inputFile.readline
userPath = "WinNT://" + dom + "/" + inLine + ",user"
set userObj = getobject ( userPath)
outMsg = inLine
'==================================================================
'== try to disable the account
'==================================================================
userObj.AccountDisabled = true
userObj.Description = strComment
userObj.setInfo
'==================================================================
'== format and write the results to the output file
'==================================================================
if err.number <> 0 then
outMsg = "Did not disable " + outMsg
else
outMsg = "Disabled " + outMsg
end if
outputFile.writeline ( outMsg )
'==================================================================
'== dump the user object and clear our msg variable
'==================================================================
set userObj = nothing
outMsg = ""
loop
'====================================================================
'== Kill our file objects
'====================================================================
outputFile.close
set outputFile = nothing
inputFile.close
set inputFile = nothing
set fso = nothing
wscript.quit ( )
'= Disable Users VBScript sample - Copyright © 2007, Dave Moats
'=
'= This sample is provided 'as-is', without any express or implied warranty.
'= In no event will the authors be held liable for any damages arising from
'= the use of this sample code.
'=
'= Permission is granted to anyone to use this sample code for any purpose,
'= including commercial applications, subject to the following restrictions:
'=
'= The origin of this code must not be misrepresented;
'= you must not claim that you wrote the original code.
'= If you use this code, an acknowledgment in the
'= documentation is requested - shown below:
'=
'= Portions Copyright © 2007, Dave Moats (http://www.davemoats.com/).
'=
'====================================================================
'====================================================================
'==
'== disableUsers.vbs - script to disable all the users in the file
'== that is provided
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")
'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
wscript.echo ( "Usage: disableUsers.vbs <Domain> <Path to Input File> <Path to Ouput file>")
dom = inputbox ( "Enter the domain where you want to disable these accounts")
inPath = inputbox ( "Enter the path to the file that contains the users you want to disable:")
outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
wscript.echo ( "Usage: disableUsers.vbs <Domain> <Path to Input File> <Path to Ouput file>")
wscript.quit ( )
else
dom = wscript.arguments.item ( 0)
inPath = wscript.arguments.item ( 1)
outPath = wscript.arguments.item ( 2)
end if
'====================================================================
'== make sure we have the info
'====================================================================
if dom = "" or inPath = "" or outPath = "" then
wscript.echo ( "There were not enough arguments passed to the script")
wscript.echo ( "Usage: disableUsers.vbs <Domain> <Path to Input File> <Path to Ouput file>")
wscript.quit ( )
end if
set inputFile = fso.opentextfile ( inPath )
set outputFile = fso.createtextfile ( outPath )
strComment = "Acct disabled on " & date
'====================================================================
'== turn off the wscript error handling - so this script can trap
'== any errors
'====================================================================
on error resume next
'====================================================================
'== loop thru the input file and process the contents
'====================================================================
do while not ( inputFile.atendofstream)
'==================================================================
'== bind to the user specified in the file
'==================================================================
inLine = inputFile.readline
userPath = "WinNT://" + dom + "/" + inLine + ",user"
set userObj = getobject ( userPath)
outMsg = inLine
'==================================================================
'== try to disable the account
'==================================================================
userObj.AccountDisabled = true
userObj.Description = strComment
userObj.setInfo
'==================================================================
'== format and write the results to the output file
'==================================================================
if err.number <> 0 then
outMsg = "Did not disable " + outMsg
else
outMsg = "Disabled " + outMsg
end if
outputFile.writeline ( outMsg )
'==================================================================
'== dump the user object and clear our msg variable
'==================================================================
set userObj = nothing
outMsg = ""
loop
'====================================================================
'== Kill our file objects
'====================================================================
outputFile.close
set outputFile = nothing
inputFile.close
set inputFile = nothing
set fso = nothing
wscript.quit ( )
Copyright © 2010 Dave Moats. All rights reserved. Links: Copyright © by their respective owners.
NO WARRANTIES EXTENDED. Void where prohibited by law. Please report any issues or broken links.
You may link to this site freely from your own site. You may quote from this site, but please include a link to the original source on the originating site.