We are in the need for a script that will search a dump .xls file and
disable AD accounts. Can any one please help on this.

Thanks

Re: Ad Disable Accounts by Richard

Richard
Wed Feb 28 08:57:16 CST 2007


<jmacd5@gmail.com> wrote in message
news:1172672371.655693.120590@v33g2000cwv.googlegroups.com...
> We are in the need for a script that will search a dump .xls file and
> disable AD accounts. Can any one please help on this.
>
> Thanks
>

Bind to each user object and use the AccountDisabled property method to
disable. If the spreadsheet has Distinguished Names (in the first column),
the code could be:
===================
' Specify spreadsheet.
strExcelPath = "c:\scripts\OldUsers.xls"

' Open spreadsheet.
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open strExcelPath

' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' Read rows until first blank in column 1.
' If first row is column headers, assign 2 to intRow.
intRow = 1
Do While (objSheet.Cells(intRow, 1).Value <> "")
' Read user Distinguished Name.
strUserDN = Trim(objSheet.Cells(intRow, 1).Value)
' Bind to user object.
Set objUser = GetObject("LDAP://" & strUserDN)
' Disable
objUser.AccountDisabled = True
' Save change to AD.
objUser.SetInfo
intRow = intRow + 1
Loop

' Close workbook.
objExcel.ActiveWorkbook.Close
============
If the spreadsheet has NT names (pre-Windows 2000 logon names), you will
need to use the NameTranslate object to convert the NT names to
Distinguished Names. More on NameTranslate here:

http://www.rlmueller.net/NameTranslateFAQ.htm

And an example VBScript program that reads NT names from a spreadsheet and
modifies the profilePath attribute of the users:

http://www.rlmueller.net/UpdateUserProfile2.htm

This program demonstrates how to use the NameTranslate object in a loop
reading names from a spreadsheet. It also demonstrates error trapping
techniques.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Ad Disable Accounts by jmacd5

jmacd5
Wed Feb 28 09:40:35 CST 2007

On Feb 28, 9:57 am, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> <jma...@gmail.com> wrote in message
>
> news:1172672371.655693.120590@v33g2000cwv.googlegroups.com...
>
> > We are in the need for a script that will search a dump .xls file and
> > disable AD accounts. Can any one please help on this.
>
> > Thanks
>
> Bind to each user object and use the AccountDisabled property method to
> disable. If the spreadsheet has Distinguished Names (in the first column),
> the code could be:
> ===================
> ' Specify spreadsheet.
> strExcelPath = "c:\scripts\OldUsers.xls"
>
> ' Open spreadsheet.
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Workbooks.Open strExcelPath
>
> ' Bind to worksheet.
> Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
>
> ' Read rows until first blank in column 1.
> ' If first row is column headers, assign 2 to intRow.
> intRow = 1
> Do While (objSheet.Cells(intRow, 1).Value <> "")
> ' Read user Distinguished Name.
> strUserDN = Trim(objSheet.Cells(intRow, 1).Value)
> ' Bind to user object.
> Set objUser = GetObject("LDAP://" & strUserDN)
> ' Disable
> objUser.AccountDisabled = True
> ' Save change to AD.
> objUser.SetInfo
> intRow = intRow + 1
> Loop
>
> ' Close workbook.
> objExcel.ActiveWorkbook.Close
> ============
> If the spreadsheet has NT names (pre-Windows 2000 logon names), you will
> need to use the NameTranslate object to convert the NT names to
> Distinguished Names. More on NameTranslate here:
>
> http://www.rlmueller.net/NameTranslateFAQ.htm
>
> And an example VBScript program that reads NT names from a spreadsheet and
> modifies the profilePath attribute of the users:
>
> http://www.rlmueller.net/UpdateUserProfile2.htm
>
> This program demonstrates how to use the NameTranslate object in a loop
> reading names from a spreadsheet. It also demonstrates error trapping
> techniques.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -http://www.rlmueller.net
> --

thanks,
We will give this a try.
Appreciate the help.