'====================================================================
'= Show Disabled 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/).
'=
'====================================================================
'====================================================================
'==
'== listDisabledUser.vbs - script to list all the users in a domain
'==                                     that are disabled
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")

'====================================================================
'== get the info required to run the script
'====================================================================
if wscript.arguments.count = 0 then
   wscript.echo ( "Usage: listDisabledUser.vbs <Domain> <Path to Ouput file>")
   domName = inputbox ( "Enter the domain that you want to list the disabled users for:")
   outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
   wscript.echo ( "Usage: listDisabledUser.vbs <Domain> <Path to Ouput file>")
   wscript.quit ( )
else
   domName = wscript.arguments.item ( 0)
   outPath = wscript.arguments.item ( 1)
end if

'====================================================================
'== Make sure we have some info
'====================================================================
if domName = "" or outPath = "" then
   wscript.echo ( "There were not enough arguments passed to the script")
   wscript.echo ( "Usage: listDisabledUser.vbs <Domain> <Path to Ouput file>")
   wscript.quit ( )
end if

'====================================================================
'== Open the base out file
'====================================================================
set outputFile = fso.createtextfile ( outPath)

on error resume next

'====================================================================
'== Bind to the NT4 domain we are interested in
'====================================================================
domPath = "WinNT://" & domName
domFilter = array ( "User")
set domObj = getobject ( domPath)

'====================================================================
'== Apply the filter to the returned object
'====================================================================
domObj.filter = domFilter

'====================================================================
'== Go through the list of groups displaying the members
'====================================================================
for each usrObj in domObj

      if usrObj.AccountDisabled = true then
         outputFile.writeline ( usrObj.name & " is disabled" )
      end if

next

'====================================================================
'== Dump the reference to the domain
'====================================================================
set domObj = nothing

'====================================================================
'== Clean up the out file reference and the file system object
'====================================================================
outputFile.close
set outputFile = nothing

set fso = nothing

wscript.quit ( )




Copyright © 2005 - 2013 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.