Hi I am using the code below to create new global security groups from names in a text file, if that file is updated with one or more names then the script run against it I get the error 'the object already exists' I can get round this using on error resume next, but would like to check for the existance of a global group within the script.
Can anyone help me out with the best way to do that?
'create new Global Groups from file c:\scripts\groups.txt
Const ForReading = 1
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
'open text file for group names
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objGGFile = objFSO.OpenTextFile("c:\scripts\groups.txt", ForReading)
'Bind to users container in domain and create new Global Groups
Do Until objGGFile.AtEndOfStream
f_str = objGGFile.ReadLine
Err.Clear
Set objOU = GetObject("LDAP://cn=users,dc=domain,dc=domain,dc=domain,dc=biz")
If Err.Number <> 0 Then
Wscript.Echo Err.Number & "--" & Err.Description
Err.Clear
End If
Set objGroup = objOU.Create("Group", "cn=" & f_str)
objGroup.Put "sAMAccountName", f_str
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.Setinfo
Loop
objGGFile.Close
Thanks
Rob
Can anyone help me out with the best way to do that?
'create new Global Groups from file c:\scripts\groups.txt
Const ForReading = 1
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
'open text file for group names
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objGGFile = objFSO.OpenTextFile("c:\scripts\groups.txt", ForReading)
'Bind to users container in domain and create new Global Groups
Do Until objGGFile.AtEndOfStream
f_str = objGGFile.ReadLine
Err.Clear
Set objOU = GetObject("LDAP://cn=users,dc=domain,dc=domain,dc=domain,dc=biz")
If Err.Number <> 0 Then
Wscript.Echo Err.Number & "--" & Err.Description
Err.Clear
End If
Set objGroup = objOU.Create("Group", "cn=" & f_str)
objGroup.Put "sAMAccountName", f_str
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.Setinfo
Loop
objGGFile.Close
Thanks
Rob