Hi All,
I'm trying to write a script that will delete Global Security groups in bulk. The script reads the group names from a file, finds it in the domain(could be in any OU, we've got multiple OUs) and deletes it.
So far this is what i got ... this is my problem ...
I'm now setting the objOU myself, i need the script to set this automatically depending on which OU the group is in the domain.
I can get the ADSPath but i can't remove the CN only, i end up with an array i need to join them back.
Could you suggest a solution or an alternative method?
Set objOU= GetObject("LDAP://q1-core.
q1.aig.net
/OU=Groups
,OU=Living
ston_NJ,OU
=AIGT,OU=Q
1,DC=q1-co
re,DC=q1,D
C=aig,DC=n
et")
The script below so far .... (have not worked on the read from file yet, trying to get the delete running 1st)
strGroup = WScript.Arguments (0)
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connec
tion")
Set objCommand = CreateObject("ADODB.Comman
d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
n = objConnection
objCommand.Properties("Pag
e Size") = 1000
objCommand.Properties("Sea
rchscope")
= ADS_SCOPE_SUBTREE
objCommandProperties("Sort
On") = "Name"
Wscript.echo "check1" + strGroup
objCommand.CommandText = _
"SELECT ADsPath, distinguishedName FROM 'LDAP://q1-core.q1.aig.net
' WHERE cn='" & strGroup &"'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strPath = objRecordSet.Fields("ADsPa
th").Value
Set objGroup = GetObject(strPath)
Set objOU= GetObject("LDAP://q1-core.
q1.aig.net
/OU=Groups
,OU=Living
ston_NJ,OU
=AIGT,OU=Q
1,DC=q1-co
re,DC=q1,D
C=aig,DC=n
et")
Wscript.Echo "Group: " & strPath
strDN = objRecordSet.Fields("disti
nguishedNa
me").Value
arrTemp = Split(strDN, ",")
strOU = arrTemp(0)
Wscript.echo strOU
objOU.Delete "group", strOU
objRecordSet.MoveNext
Loop
Start Free Trial