Hello all:
I have written a vbs script that was supposed to loop through an excel spreadsheet and delete users' account from active directory. I'm not getting any errors when I run the script but it also doesn't delete the accounts that are listed in the active directory. I'm using Windows 2003 EE and the script is below. If you guys have any ideas as to why the script is not deleteing the accounts, would be greatly appreciated.
Thanks.
'Parent container of new user
Dim oContainer
'created user
Dim oUser
'Set the file type and location where we are going to get the data from
on error resume next
set x = getobject(,"excel.application")
If err.number<> 0 Then
set x = createObject("excel.application")
err.clear
end If
set objWorkbook = x.Workbooks.Open("D:\accts1.xls")
If err.number <> 0 Then
wscript.echo "Source file not found. Cannot proceed with importing into Active Directory. Operation aborted."
x.quit : set x=nothing : wscript.quit
end If
on error goto 0
set y = objWorkbook.activesheet
'Start from the second row of the spreadsheet
r = 2
'Set the path to the appropriate network.
set oContainer = GetObject("LDAP://OU=Test,OU=AllUsers,DC=domain,DC=com")
do until len(y.cells(r, 1).value) = 0
with y
first_name = .cells(r, 1).value
last_name = .cells(r, 2).value
end with
'Add users data
fullName = first_name & " " & last_name
on error resume next
If Err.Number <> 0 And Err.Number <> -2147019886 Then
'If there is an error then show error otherwise display confirmation texts in the assigned cells
x.cells(r, 17).value = err.number & ": " & "ID creation error"
err.clear
Else
with oContainer
.Delete "user","CN=" & fullName
end with
with y
.cells(r, 5).value = "deleted"
end with
End if
set oUser=nothing
on error goto 0
r = r + 1
Loop
Set grp = Nothing
Set oContainer = nothing
'tidying up xls
set y=nothing
'objWorkbook.save
'objWorkbook.close
set objWorkbook = nothing
set x = nothing
msgbox "Successfully deleted users from Active Directory"
"Behind every great fortune there lies a great crime", Honore De Balzac
I have written a vbs script that was supposed to loop through an excel spreadsheet and delete users' account from active directory. I'm not getting any errors when I run the script but it also doesn't delete the accounts that are listed in the active directory. I'm using Windows 2003 EE and the script is below. If you guys have any ideas as to why the script is not deleteing the accounts, would be greatly appreciated.
Thanks.
'Parent container of new user
Dim oContainer
'created user
Dim oUser
'Set the file type and location where we are going to get the data from
on error resume next
set x = getobject(,"excel.application")
If err.number<> 0 Then
set x = createObject("excel.application")
err.clear
end If
set objWorkbook = x.Workbooks.Open("D:\accts1.xls")
If err.number <> 0 Then
wscript.echo "Source file not found. Cannot proceed with importing into Active Directory. Operation aborted."
x.quit : set x=nothing : wscript.quit
end If
on error goto 0
set y = objWorkbook.activesheet
'Start from the second row of the spreadsheet
r = 2
'Set the path to the appropriate network.
set oContainer = GetObject("LDAP://OU=Test,OU=AllUsers,DC=domain,DC=com")
do until len(y.cells(r, 1).value) = 0
with y
first_name = .cells(r, 1).value
last_name = .cells(r, 2).value
end with
'Add users data
fullName = first_name & " " & last_name
on error resume next
If Err.Number <> 0 And Err.Number <> -2147019886 Then
'If there is an error then show error otherwise display confirmation texts in the assigned cells
x.cells(r, 17).value = err.number & ": " & "ID creation error"
err.clear
Else
with oContainer
.Delete "user","CN=" & fullName
end with
with y
.cells(r, 5).value = "deleted"
end with
End if
set oUser=nothing
on error goto 0
r = r + 1
Loop
Set grp = Nothing
Set oContainer = nothing
'tidying up xls
set y=nothing
'objWorkbook.save
'objWorkbook.close
set objWorkbook = nothing
set x = nothing
msgbox "Successfully deleted users from Active Directory"
"Behind every great fortune there lies a great crime", Honore De Balzac