'====================================================================
'= Enable 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/).
'=
'====================================================================
'====================================================================
'==
'==    enableUsers.vbs - script to enable 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: enableUsers.vbs <Path to Input File> <Path to Ouput file>")
   inPath = inputbox ( "Enter the path to the file that contains the users you want to enable:")
   outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
   wscript.echo ( "Usage: enableUsers.vbs <Path to Input File> <Path to Ouput file>")
   wscript.quit ( )
else
   inPath = wscript.arguments.item ( 0)
   outPath = wscript.arguments.item ( 1)
end if

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

set inputFile = fso.opentextfile ( inPath )
set outputFile = fso.createtextfile ( outPath )

'====================================================================
'== turn off the wscript error handling - so the script can trap
'== any errors
'====================================================================
on error resume next

'====================================================================
'== Now loop thru the file and process the contents
'====================================================================
do while not ( inputFile.atendofstream)

   '==================================================================
   '== bind to the user specified in the file
   '==================================================================
   inLine = inputFile.readline
  
   userPath = "WinNT://" + inLine + ",user"
  
   set userObj = getobject ( userPath)

   outMsg = userObj.Name

   '==================================================================
   '== try to enable the account
   '==================================================================
   userObj.AccountDisabled = false
   userObj.Description = " "

   userObj.setInfo

   '==================================================================
   '== format and write the results to the output file
   '==================================================================
   if err.number <> 0 then
      outMsg = "Did not enable " + outMsg
   else
      outMsg = "Enabled " + 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 © 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.