Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 21st, 2008, 10:51 AM
VBS_Noob VBS_Noob is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 5 VBS_Noob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 32 sec
Reputation Power: 0
VBScript - Add users to Domain group based on attribute

I'm looking to write a little code I can run weekly that will be able to update a Distribution list so that any new users who have the job title "Contractors" will be placed into an existing DL name "DL_Contractors" Existing members who have had their title changed to anything else should also be removed.

I've been able to write the following to purge all users from the group. If it can be written by a guru that it doesn't need to dump existing members who still match the criteria that would be great!

Code:
 Const ADS_PROPERTY_CLEAR = 1 
 
Set objGroup = GetObject("LDAP://CN=DL_Conractors,OU=Groups,DC=testdomain,DC=com") 
 
objGroup.PutEx ADS_PROPERTY_CLEAR, "member", 0
objGroup.SetInfo


How do I write the part which enumerates all User objects regardless of their location in AD and if their title = "Contractor" add them to the group.

Thank you in advance

Reply With Quote
  #2  
Old August 21st, 2008, 08:56 PM
q97 q97 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: Brisvegas
Posts: 276 q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 41 m 49 sec
Reputation Power: 37
I think if you dig through some of my early posts, you'll find code I wrote for a web system using vbscript, which might have some useful info...been too long since I've looked at it but there might be some stuff there that you may find quite useful.

Reply With Quote
  #3  
Old August 22nd, 2008, 10:10 AM
VBS_Noob VBS_Noob is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 5 VBS_Noob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by q97
I think if you dig through some of my early posts, you'll find code I wrote for a web system using vbscript, which might have some useful info...been too long since I've looked at it but there might be some stuff there that you may find quite useful.


Thanks q97. I quickly browsed your earlier posts and saw the code you wrote for the web system. Looks very slick, but didn't see what I needed.

Reply With Quote
  #4  
Old August 22nd, 2008, 02:47 PM
VBS_Noob VBS_Noob is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 5 VBS_Noob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 32 sec
Reputation Power: 0
Update

Below is some code I've found/modified, but I've been unable to make it work properly. I don't get any errors, but it doesn't seem to do anything and it doesn't end.

Code:
On Error Resume Next
strgroup = "LDAP://cn=contractorTest,ou=Groups,dc=domain,dc=com"
Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = _
    "SELECT ADsPath FROM strgroup WHERE objectCategory='user' " & _ 
	"AND title='Contractor'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Set objGroup = GetObject(strgroupname)

Do Until objRecordSet.EOF
    objGroup.Add(objRecordSet.Fields("ADsPath").Value)
    objRecordSet.MoveNext
Loop


Thanks in advance

Reply With Quote
  #5  
Old August 24th, 2008, 08:55 PM
q97 q97 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: Brisvegas
Posts: 276 q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 41 m 49 sec
Reputation Power: 37
Watch your syntax:

Code:
"SELECT ADsPath FROM strgroup WHERE objectCategory='user' " & _ 
	"AND title='Contractor'"


Should be:

Code:
"SELECT ADsPath FROM " & strgroup & "  WHERE objectCategory='user' " & _ 
	"AND title='Contractor'"


Does that work?

Reply With Quote
  #6  
Old October 21st, 2008, 03:26 AM
keep_it_simple's Avatar
keep_it_simple keep_it_simple is offline
KIS
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jul 2007
Location: USA
Posts: 1,185 keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)keep_it_simple User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 12 h 19 m 12 sec
Reputation Power: 490
Send a message via Yahoo to keep_it_simple
you are also missng single quotes around the ldap string...plus if there are no recs returned you do not have a condition...and you are missing the splat(*) for title

i am afraid the code within the do while loop will not do what you want...


you'll probably find the MS repository of great use....click active directory then find the example you want...if still having problems...post back...good luck


note...you can get the root on-the-fly...see function below...

and for debugging...comment out the on error resume next

http://www.microsoft.com/technet/sc...t.mspx?mfr=true

Code:
  Function ReturnRootDSE
   Set oRootDSE = GetObject("LDAP://RootDSE")
   ReturnRootDSE = oRootDSE.Get("defaultNamingContext")
   Set oRootDSE = Nothing   
  End Function

'On Error Resume Next

strRootDSE ="LDAP://" &  ReturnRootDSE
strgroup = "LDAP://cn=contractorTest,ou=Groups," & strRootDSE


Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = _
    "SELECT ADsPath " & _
    "FROM '" & strgroup & "' " & _
    "WHERE objectCategory='user' AND title='Contractor*'"

Set objRecordSet = objCommand.Execute

If Not objRecordSet.EOF Then

Set objGroup = GetObject(objRecordSet("adspath"))

Do Until objRecordSet.EOF
    objGroup.Add(objRecordSet.Fields("ADsPath").Value)
    objRecordSet.MoveNext
Loop

Else
 msgBox("No recs")

End If
__________________
Please give respect to those that helped solve an issue by clicking on the reputation icon

Last edited by keep_it_simple : October 21st, 2008 at 03:35 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > VBScript - Add users to Domain group based on attribute


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT