Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2577
  • Last Modified:

Vbscript to disable AD user accounts

Hi have got a list of users (first name last name) in an execl document, username could be firstname.lastname or lastname first initial EG dave.lane or laned. There are a few hundred users, i want to check each account to make sure it is disabled and if it isnt to disable it. Does anyone have a script that would read a document and do whats needed?
0
k3eper
Asked:
k3eper
  • 12
  • 8
  • 2
1 Solution
 
calepantkeCommented:
I don't have the code to export what you need. But the idea would be to create a comma  delimited file and then import it using CSVDE. 
http://www.computerperformance.co.uk/Logon/Logon_CSVDE_import.htm
http://technet.microsoft.com/en-us/library/cc732101.aspx


0
 
k3eperAuthor Commented:
Arr ok think it will probably be faster for me to do it all manually than learn how to work the comma delimited files ect. Thanks i guess
0
 
calepantkeCommented:
For some reason, I read this thread as ADDing a user... Darn mornings. Sorry about that. I'll let someone else answer this. 

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
k3eperAuthor Commented:
^_^ thats ok, hope someone can help out save me alot of hours
0
 
k3eperAuthor Commented:
Guess no one can help?
0
 
sirbountyCommented:
Think this should do it for you...
strFile = "C:\Folder\Disabled_Users.xls"
strOutput = "C:\Folder\Disabled Users Report.txt"
 
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(strOutput)
 
LoadUsers()
FindUsers()
 
objLog.Close
Set objLog = Nothing
Set objFSO = Nothing
Set dicData = Nothing
wscript.quit
 
Sub LoadUsers()
  Dim objExcel : Set objExcel = CreateObject("Excel.Application")
  Dim objWorkbook : Set objWorkbook = objExcel.Workbooks.Open (strFile)
 
  intRow = 2 ' Assumes a header row
 
  Do Until objExcel.Cells(intRow,1).Value = "" 'loop until colA is empty
    dicData.Add objExcel.Cells(intRow, 1).Value, Nothing
    intRow = intRow + 1
  Loop
 
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing
End Sub
 
Sub FindUsers()
  Const ADS_SCOPE_SUBTREE = 2
  Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
  Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
  Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
  Dim objCmd : Set objCmd = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCmd.ActiveConnection = objConnection
 
  objCmd.Properties("Page Size") = 1000
  objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
  For each item in dicData.Keys
    objCmd.CommandText = "Select ADsPath From '" & objDomain.ADsPath & "' Where objectCategory='user' And sAMAccountName='" & item & "'"
    Dim objRS : Set objRS = objCmd.Execute
    objRS.MoveFirst
    objLog.WriteLine "Verifying " & item
    If Not objRS.EOF Then
      objLog.WriteLine vbTab & "found " & item  
      Dim objUser : Set objUser = GetObject(objRS.Fields(0).Value)
      If Not objUser.AccountDisabled Then
        objLog.WriteLine vbTab & item & " is not disabled"
        On Error Resume Next
        objUser.AccountDisabled = True
        objUser.SetInfo
        If Err.Number <> 0 Then
          objLog.WriteLine vbTab & "Unable to disable " & item
        Else
          objLog.WriteLine vbTab & item & " now disabled."
        End If
      Else
        objLog.WriteLine vbTab & item & " already disabled."
      End If
      On Error Goto 0
    Else 
      objLog.WriteLine vbTab & "could not locate " & item
    End If
  Set objUser = Nothing
  Set objRS = Nothing
  Next
  Set objCmd = Nothing
  Set objConnection = Nothing
  Set objDomain = Nothing
  Set objRoot = Nothing
End Sub

Open in new window

0
 
k3eperAuthor Commented:
Could you explain how it works? Does it read first line of xl doc or first and second maybe? Ill have a play with it thank you once again Sirbounty
0
 
sirbountyCommented:
I've added some comments to it this time.
It skips the first line, which is assumed to be a header row, but you can change intRow = 2 to be = 1 instead to read the first row.
It reads to the end, builds a collection, and then loops through that to try and find each account and verify it's disabled.
'==============
'Two custom-defined variables:
'Input file which is the Excel sheet and output file which writes a report for you.
'==============
strFile = "C:\Folder\Disabled_Users.xls"
strOutput = "C:\Folder\Disabled Users Report.txt"
 
'==============
'Global assignments
'Dictionary temporarily holds the data
'FSO is necessary for communicating with the file system structure
'objLog is the object to use when writing to the output file
'==============
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(strOutput)
 
LoadUsers() 'Run LoadUsers subroutine to populate the dictionary with all users found in the spreadsheet
FindUsers() 'Locate the users and disable then
 
'==============
'Close output file and clean up variable declarations, then quit
'==============
objLog.Close
Set objLog = Nothing
Set objFSO = Nothing
Set dicData = Nothing
wscript.quit
 
 
Sub LoadUsers()
  '==============
  'Assignemnts to communicate with Excel
  '==============
  Dim objExcel : Set objExcel = CreateObject("Excel.Application")
  Dim objWorkbook : Set objWorkbook = objExcel.Workbooks.Open (strFile)
 
  intRow = 2 ' Assumes a header row and skips the data on line 1 - adjust if no header row to 1
 
  '==============
  'Loop setup to read until no more data is found.  Each cell data is added to the dictionary list
  '==============
  Do Until objExcel.Cells(intRow,1).Value = "" 'loop until colA is empty
    dicData.Add objExcel.Cells(intRow, 1).Value, Nothing
    intRow = intRow + 1
  Loop
 
  '==============
  'Quit Excel and cleanup variables
  '==============
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing
End Sub
 
Sub FindUsers()
  '==============
  'AD variables that allow subtree searching from the root of the directory - only works with the current forest
  '==============
  Const ADS_SCOPE_SUBTREE = 2
  Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
  Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
  Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
  Dim objCmd : Set objCmd = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCmd.ActiveConnection = objConnection
  objCmd.Properties("Page Size") = 1000
  objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
  '==============
  'Now loop through all the dictionary elements attempting to find the user with the matching logon name (SAMAccountName)
  'If found, the information is recorded in the output file and if the account is not disabled, it will be.
  '==============
  For each item in dicData.Keys
    objCmd.CommandText = "Select ADsPath From '" & objDomain.ADsPath & "' Where objectCategory='user' And sAMAccountName='" & item & "'"
    Dim objRS : Set objRS = objCmd.Execute
    objRS.MoveFirst
    objLog.WriteLine "Verifying " & item
    If Not objRS.EOF Then
      objLog.WriteLine vbTab & "found " & item  
      Dim objUser : Set objUser = GetObject(objRS.Fields(0).Value)
      If Not objUser.AccountDisabled Then
        objLog.WriteLine vbTab & item & " is not disabled"
        On Error Resume Next
        objUser.AccountDisabled = True
        objUser.SetInfo
        If Err.Number <> 0 Then
          objLog.WriteLine vbTab & "Unable to disable " & item
        Else
          objLog.WriteLine vbTab & item & " now disabled."
        End If
      Else
        objLog.WriteLine vbTab & item & " already disabled."
      End If
      On Error Goto 0
    Else 
      objLog.WriteLine vbTab & "could not locate " & item
    End If
  Set objUser = Nothing
  Set objRS = Nothing
  Next
  '===============
  'variable cleanup
  '===============  
  Set objCmd = Nothing
  Set objConnection = Nothing
  Set objDomain = Nothing
  Set objRoot = Nothing
End Sub

Open in new window

0
 
k3eperAuthor Commented:
Arr great thank you, ill have a play with it and see if i can get it to work.
0
 
k3eperAuthor Commented:
Ok ive tried afew things, removed all data in sheet except the names of users. I run the script and the output is a blank document. Ive got he xls data in 2 rows and various coloums. First name then lastname. Then next row, ect.
0
 
sirbountyCommented:
Reread your question - I may have misinterpreted, so please try this slight adjustment...
'==============
'Two custom-defined variables:
'Input file which is the Excel sheet and output file which writes a report for you.
'==============
strFile = "C:\Folder\Disabled_Users.xls"
strOutput = "C:\Folder\Disabled Users Report.txt"
 
'==============
'Global assignments
'Dictionary temporarily holds the data
'FSO is necessary for communicating with the file system structure
'objLog is the object to use when writing to the output file
'==============
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(strOutput)
 
LoadUsers() 'Run LoadUsers subroutine to populate the dictionary with all users found in the spreadsheet
FindUsers() 'Locate the users and disable then
 
'==============
'Close output file and clean up variable declarations, then quit
'==============
objLog.Close
Set objLog = Nothing
Set objFSO = Nothing
Set dicData = Nothing
wscript.quit
 
 
Sub LoadUsers()
  '==============
  'Assignemnts to communicate with Excel
  '==============
  Dim objExcel : Set objExcel = CreateObject("Excel.Application")
  Dim objWorkbook : Set objWorkbook = objExcel.Workbooks.Open (strFile)
 
  intRow = 2 ' Assumes a header row and skips the data on line 1 - adjust if no header row to 1
 
  '==============
  'Loop setup to read until no more data is found.  Each cell data is added to the dictionary list
  '==============
  Do Until objExcel.Cells(intRow,1).Value = "" 'loop until colA is empty
    dicData.Add objExcel.Cells(intRow, 1).Value, Nothing
    intRow = intRow + 1
  Loop
 
  '==============
  'Quit Excel and cleanup variables
  '==============
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing
End Sub
 
Sub FindUsers()
  '==============
  'AD variables that allow subtree searching from the root of the directory - only works with the current forest
  '==============
  Const ADS_SCOPE_SUBTREE = 2
  Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
  Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
  Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
  Dim objCmd : Set objCmd = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCmd.ActiveConnection = objConnection
  objCmd.Properties("Page Size") = 1000
  objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
  '==============
  'Now loop through all the dictionary elements attempting to find the user with the matching logon name (SAMAccountName)
  'If found, the information is recorded in the output file and if the account is not disabled, it will be.
  '==============
  For each item in dicData.Keys
    Dim blnFound : blnFound = False
    Dim arrSAM : arrSAM = Array(item & "." & dicData(item), dicData(item) & Left(item, 1))
    For Each strSAM in arrSAM
      objCmd.CommandText = "Select ADsPath From '" & objDomain.ADsPath & "' Where objectCategory='user' And sAMAccountName='" & strSAM & "'"
      Dim objRS : Set objRS = objCmd.Execute
      objRS.MoveFirst
      objLog.WriteLine "Testing for " & strSAM
      If Not objRS.EOF Then
        objLog.WriteLine vbTab & "found " & strSAM  
        Dim objUser : Set objUser = GetObject(objRS.Fields(0).Value)
        If Not objUser.AccountDisabled Then
          objLog.WriteLine vbTab & strSAM & " is not disabled"
          On Error Resume Next
          objUser.AccountDisabled = True
          objUser.SetInfo
          If Err.Number <> 0 Then
            objLog.WriteLine vbTab & "Unable to disable " & strSAM
          Else
            objLog.WriteLine vbTab & strSAM & " now disabled."
          End If
        Else
          objLog.WriteLine vbTab & strSAM & " already disabled."
        End If
        On Error Goto 0
      Else 
        objLog.WriteLine vbTab & "could not locate " & strSAM
      End If
      objLog.WriteLine
      Set objUser = Nothing
      Set objRS = Nothing
    Next
  Next
objLog.Close
  '===============
  'variable cleanup
  '===============  
  Set objCmd = Nothing
  Set objConnection = Nothing
  Set objDomain = Nothing
  Set objRoot = Nothing
End Sub

Open in new window

0
 
k3eperAuthor Commented:
Im still getting a blank output and the test names im using arnt being disabled. Is there away to specify a domain to disable in or search for users in? Thanks so much for the help so far.
0
 
sirbountyCommented:
Did you change the first two variables to point to the correct folder/files?
We could change it a bit to direct it to a specific domain, but this should be searching the entire forest.
Try this version first - please run it using the cscript engine (i.e. cscript c:\folder\yourfile.vbs)
It should display some processing lines to hopefully help identify the problem...let me know.
'==============
'Two custom-defined variables:
'Input file which is the Excel sheet and output file which writes a report for you.
'==============
strFile = "C:\Folder\Disabled_Users.xls"
strOutput = "C:\Folder\Disabled Users Report.txt"
 
'==============
'Global assignments
'Dictionary temporarily holds the data
'FSO is necessary for communicating with the file system structure
'objLog is the object to use when writing to the output file
'==============
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(strOutput)
 
LoadUsers() 'Run LoadUsers subroutine to populate the dictionary with all users found in the spreadsheet
FindUsers() 'Locate the users and disable then
 
'==============
'Close output file and clean up variable declarations, then quit
'==============
objLog.Close
Set objLog = Nothing
Set objFSO = Nothing
Set dicData = Nothing
wscript.quit
 
 
Sub LoadUsers()
  '==============
  'Assignemnts to communicate with Excel
  '==============
  Dim objExcel : Set objExcel = CreateObject("Excel.Application")
  Dim objWorkbook : Set objWorkbook = objExcel.Workbooks.Open (strFile)
 
  intRow = 2 ' Assumes a header row and skips the data on line 1 - adjust if no header row to 1
 
  '==============
  'Loop setup to read until no more data is found.  Each cell data is added to the dictionary list
  '==============
  Do Until objExcel.Cells(intRow,1).Value = "" 'loop until colA is empty
    wscript.echo "Adding " & objExcel.Cells(intRow, 1).Value
    dicData.Add objExcel.Cells(intRow, 1).Value, Nothing
    intRow = intRow + 1
  Loop
 
  '==============
  'Quit Excel and cleanup variables
  '==============
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing
End Sub
 
Sub FindUsers()
  '==============
  'AD variables that allow subtree searching from the root of the directory - only works with the current forest
  '==============
  Const ADS_SCOPE_SUBTREE = 2
  Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
  Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
  Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
  Dim objCmd : Set objCmd = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCmd.ActiveConnection = objConnection
  objCmd.Properties("Page Size") = 1000
  objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
  '==============
  'Now loop through all the dictionary elements attempting to find the user with the matching logon name (SAMAccountName)
  'If found, the information is recorded in the output file and if the account is not disabled, it will be.
  '==============
  For each item in dicData.Keys
    Dim blnFound : blnFound = False
    Dim arrSAM : arrSAM = Array(item & "." & dicData(item), dicData(item) & Left(item, 1))
    For Each strSAM in arrSAM
      objCmd.CommandText = "Select ADsPath From '" & objDomain.ADsPath & "' Where objectCategory='user' And sAMAccountName='" & strSAM & "'"
      wscript.echo "Searching for " & strSAM
      Dim objRS : Set objRS = objCmd.Execute
      objRS.MoveFirst
      objLog.WriteLine "Testing for " & strSAM
      If Not objRS.EOF Then
        wscript.echo "Found " & strSAM
        objLog.WriteLine vbTab & "found " & strSAM  
        Dim objUser : Set objUser = GetObject(objRS.Fields(0).Value)
        If Not objUser.AccountDisabled Then
          wscript.echo vbTab & "...account is not disabled."
          objLog.WriteLine vbTab & strSAM & " is not disabled"
          On Error Resume Next
          objUser.AccountDisabled = True
          objUser.SetInfo
          wscript.echo vbTab & "...now it should be."
          If Err.Number <> 0 Then
            objLog.WriteLine vbTab & "Unable to disable " & strSAM
          Else
            objLog.WriteLine vbTab & strSAM & " now disabled."
          End If
        Else
          objLog.WriteLine vbTab & strSAM & " already disabled."
        End If
        On Error Goto 0
      Else 
        objLog.WriteLine vbTab & "could not locate " & strSAM
      End If
      objLog.WriteLine
      Set objUser = Nothing
      Set objRS = Nothing
    Next
  Next
 
  '===============
  'variable cleanup
  '===============  
  Set objCmd = Nothing
  Set objConnection = Nothing
  Set objDomain = Nothing
  Set objRoot = Nothing
End Sub

Open in new window

0
 
k3eperAuthor Commented:
Yes im altering the said lines. im getting this

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Adding Jennifer
Adding Liz
Adding Hayley
Adding Elizabeth
Adding Sarah
Adding Judy
Adding Sheila
Adding Barbara
Adding Sandra
Adding Sylvia
Adding Liv
Adding Irene
Adding Sandra
C:\Documents and Settings\laned\My Documents\disable.vbs(45, 5) Microsoft VBScri
pt runtime error: This key is already associated with an element of this collect
ion


C:\Documents and Settings\laned>"C:\Documents and Settings\laned\My Documents\di
sable.vbs"
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Adding darryl
Adding laned
C:\Documents and Settings\laned\My Documents\disable.vbs(78, 18) Microsoft VBScr
ipt runtime error: Object variable not set

I tried 2 different excel docs
0
 
sirbountyCommented:
Please tell me how your spreadsheet is laid out - could you post a small version of it?
0
 
k3eperAuthor Commented:
Forename      Surname
Jennifer      Wilson
Liz      Lorimer
Hayley      Wallace
Elizabeth      Morris
Sarah      Bean
Judy      Keutenius
Sheila      Ball

I tried a few different ways but i recieve the list in this kinda format with various other details. But those are the first few lines left to right
0
 
sirbountyCommented:
Ahh, so it looks like it's laid out columnA = Firstname and columnB = Lastname?
That changes things a bit - I'll update the code once you confirm...        
0
 
sirbountyCommented:
You can try this out...
'==============
'Two custom-defined variables:
'Input file which is the Excel sheet and output file which writes a report for you.
'==============
strFile = "C:\Folder\Disabled_Users.xls"
strOutput = "C:\Folder\Disabled Users Report.txt"
 
'==============
'Global assignments
'Dictionary temporarily holds the data
'FSO is necessary for communicating with the file system structure
'objLog is the object to use when writing to the output file
'==============
Dim dicData : Set dicData = CreateObject("Scripting.Dictionary")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(strOutput)
 
LoadUsers() 'Run LoadUsers subroutine to populate the dictionary with all users found in the spreadsheet
FindUsers() 'Locate the users and disable then
 
'==============
'Close output file and clean up variable declarations, then quit
'==============
objLog.Close
Set objLog = Nothing
Set objFSO = Nothing
Set dicData = Nothing
wscript.quit
 
 
Sub LoadUsers()
  '==============
  'Assignemnts to communicate with Excel
  '==============
  Dim objExcel : Set objExcel = CreateObject("Excel.Application")
  Dim objWorkbook : Set objWorkbook = objExcel.Workbooks.Open (strFile)
 
  intRow = 2 ' Assumes a header row and skips the data on line 1 - adjust if no header row to 1
 
  '==============
  'Loop setup to read until no more data is found.  Each cell data is added to the dictionary list
  '==============
  Do Until objExcel.Cells(intRow,1).Value = "" 'loop until colA is empty
    wscript.echo "Adding " & objExcel.Cells(intRow, 1).Value & " " & objExcel.Cells(intRow,2).Value
    dicData.Add objExcel.Cells(intRow, 1).Value & "_" & objExcel.Cells(intRow,2).Value, Nothing
    intRow = intRow + 1
  Loop
 
  '==============
  'Quit Excel and cleanup variables
  '==============
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing
End Sub
 
Sub FindUsers()
  '==============
  'AD variables that allow subtree searching from the root of the directory - only works with the current forest
  '==============
  Const ADS_SCOPE_SUBTREE = 2
  Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
  Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
  Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
  Dim objCmd : Set objCmd = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCmd.ActiveConnection = objConnection
  objCmd.Properties("Page Size") = 1000
  objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
  '==============
  'Now loop through all the dictionary elements attempting to find the user with the matching logon name (SAMAccountName)
  'If found, the information is recorded in the output file and if the account is not disabled, it will be.
  '==============
  For each item in dicData.Keys
    Dim blnFound : blnFound = False
    arrData = Split(item,"_")
    Dim arrSAM : arrSAM = Array(arrData(0) & "." & arrData(1), arrData(1) & Left(arrData(0), 1))
    For Each strSAM in arrSAM
      objCmd.CommandText = "Select ADsPath From '" & objDomain.ADsPath & "' Where objectCategory='user' And sAMAccountName='" & strSAM & "'"
      wscript.echo "Searching for " & strSAM
      Dim objRS : Set objRS = objCmd.Execute
      objRS.MoveFirst
      objLog.WriteLine "Testing for " & strSAM
      If Not objRS.EOF Then
        wscript.echo "Found " & strSAM
        objLog.WriteLine vbTab & "found " & strSAM  
        Dim objUser : Set objUser = GetObject(objRS.Fields(0).Value)
        If Not objUser.AccountDisabled Then
          wscript.echo vbTab & "...account is not disabled."
          objLog.WriteLine vbTab & strSAM & " is not disabled"
          On Error Resume Next
          objUser.AccountDisabled = True
          objUser.SetInfo
          wscript.echo vbTab & "...now it should be."
          If Err.Number <> 0 Then
            objLog.WriteLine vbTab & "Unable to disable " & strSAM
          Else
            objLog.WriteLine vbTab & strSAM & " now disabled."
          End If
        Else
          objLog.WriteLine vbTab & strSAM & " already disabled."
        End If
        On Error Goto 0
      Else 
        objLog.WriteLine vbTab & "could not locate " & strSAM
      End If
      objLog.WriteLine
      Set objUser = Nothing
      Set objRS = Nothing
    Next
  Next
 
  '===============
  'variable cleanup
  '===============  
  Set objCmd = Nothing
  Set objConnection = Nothing
  Set objDomain = Nothing
  Set objRoot = Nothing
End Sub

Open in new window

0
 
k3eperAuthor Commented:
Thanks for all the help. Ill try testing it again.
0
 
k3eperAuthor Commented:
Ive given up on this thanks for all the help
0
 
sirbountyCommented:
Hmm - over 3 months of no feedback, I'm not sure how I could've helped you further...
0
 
k3eperAuthor Commented:
Sorry Ive been rather busy (had an op etc) not been back to work for a while and not been on a pc till recently. Sorry about the delay and once again thank you all
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 12
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now