Hi
I have a script to move users to ou's using command line arguments, I run it like this scriptmane.vbs ouname users, because I am using unamed arguments it has to be done in that order. Here is the script
'Move users to OU using command line arguments
On Error Resume Next
Set objArgs = Wscript.Arguments
strOU = objArgs(0)
For I = 0 To objArgs.Count - 1
strUser = objArgs(I)
f_user = "LDAP://cn=" & strUser & ",cn=users,dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
f_ou = "LDAP://ou=" & strOU & ",dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
Err.Clear
Set objOU = GetObject(f_ou)
If Err Then
AdsiErr()
Else
Err.Clear
objou.MoveHere f_user, vbNullString
If Err Then
AdsiErr()
Else
Wscript.Echo "User " & strUser & " Has been added to the OU " & strOU
End If
End If
Next
Sub AdsiErr()
If Err.Number = &h80072030 Then
Wscript.Echo "Please check OU Name or User Name that object does not exist"
On Error Resume Next
Else
e = Hex(Err.Number)
Wscript.Echo Err.Number & " " & e & " " & Err.Description
Wscript.Quit
End If
End Sub
I want to use named arguments so that I can enter the arguments in in any order to save mistakes so I have come up with this
'Move users to OU using command line arguments
On Error Resume Next
Set colNamedArguments = Wscript.Arguments.Named
strOU = colNamedArguments.Item("OU")
'For I = 0 To colNamedArguments.Count - 1
strUser = colNamedArguments.Item("User")
f_user = "LDAP://cn=" & strUser & ",cn=users,dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
f_ou = "LDAP://ou=" & strOU & ",dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
Err.Clear
Set objOU = GetObject(f_ou)
If Err Then
AdsiErr()
Else
Err.Clear
objou.MoveHere f_user, vbNullString
If Err Then
AdsiErr()
Else
Wscript.Echo "User " & strUser & " Has been added to the OU " & strOU
End If
End If
'Next
Sub AdsiErr()
If Err.Number = &h80072030 Then
Wscript.Echo "Please check OU Name or User Name that object does not exist"
On Error Resume Next
Else
e = Hex(Err.Number)
Wscript.Echo Err.Number & " " & e & " " & Err.Description
Wscript.Quit
End If
End Sub
I want to be able to move multiple users like this
Scriptname.vbs /server:servername /user:username /user:username
but as the script stands it only recognises and moves the first user, I have tried to find information but I am stuck, any help would be great
Thanks
Rob
I have a script to move users to ou's using command line arguments, I run it like this scriptmane.vbs ouname users, because I am using unamed arguments it has to be done in that order. Here is the script
'Move users to OU using command line arguments
On Error Resume Next
Set objArgs = Wscript.Arguments
strOU = objArgs(0)
For I = 0 To objArgs.Count - 1
strUser = objArgs(I)
f_user = "LDAP://cn=" & strUser & ",cn=users,dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
f_ou = "LDAP://ou=" & strOU & ",dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
Err.Clear
Set objOU = GetObject(f_ou)
If Err Then
AdsiErr()
Else
Err.Clear
objou.MoveHere f_user, vbNullString
If Err Then
AdsiErr()
Else
Wscript.Echo "User " & strUser & " Has been added to the OU " & strOU
End If
End If
Next
Sub AdsiErr()
If Err.Number = &h80072030 Then
Wscript.Echo "Please check OU Name or User Name that object does not exist"
On Error Resume Next
Else
e = Hex(Err.Number)
Wscript.Echo Err.Number & " " & e & " " & Err.Description
Wscript.Quit
End If
End Sub
I want to use named arguments so that I can enter the arguments in in any order to save mistakes so I have come up with this
'Move users to OU using command line arguments
On Error Resume Next
Set colNamedArguments = Wscript.Arguments.Named
strOU = colNamedArguments.Item("OU")
'For I = 0 To colNamedArguments.Count - 1
strUser = colNamedArguments.Item("User")
f_user = "LDAP://cn=" & strUser & ",cn=users,dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
f_ou = "LDAP://ou=" & strOU & ",dc=rldom,dc=modnetwork,dc=vernons,dc=biz"
Err.Clear
Set objOU = GetObject(f_ou)
If Err Then
AdsiErr()
Else
Err.Clear
objou.MoveHere f_user, vbNullString
If Err Then
AdsiErr()
Else
Wscript.Echo "User " & strUser & " Has been added to the OU " & strOU
End If
End If
'Next
Sub AdsiErr()
If Err.Number = &h80072030 Then
Wscript.Echo "Please check OU Name or User Name that object does not exist"
On Error Resume Next
Else
e = Hex(Err.Number)
Wscript.Echo Err.Number & " " & e & " " & Err.Description
Wscript.Quit
End If
End Sub
I want to be able to move multiple users like this
Scriptname.vbs /server:servername /user:username /user:username
but as the script stands it only recognises and moves the first user, I have tried to find information but I am stuck, any help would be great
Thanks
Rob