Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Binding to OU in active directory

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,23747
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Binding to OU in active directory
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Binding to OU in active directory - 7/19/2005 2:45:04 AM   
  jraisor

 

Posts: 39
Score: 0
Joined: 4/29/2005
From:
Status: offline
    Howdy me again. :)

Ok so i've had success with creating a script that will see what Global Group a PC belongs to and then map a printer accordingly. Well i'd like to do away with putting PC's in global groups and just have the script search what OU the computer belongs to and map that way. Here is my current part of the script that accomplishes the mapping by group. can anyone help me with going to mapping by OU?  I've tried to edit  current lines to somthing like Set objGroup2 = GetObject("LDAP://ou= HR PC's,ou=GI PC's,ou=GI,dc=app,dc=com") but it gives me errors saying there is no such object on the server.

I really would be grateful for any input. Thanks
***************************************************************************
strComputer = objNetwork.ComputerName
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strComputer & "$"
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Bind to the computer object in Active Directory with the LDAP
' provider.
Set objComputer = GetObject("LDAP://" & strComputerDN)

' Bind to a group object in Active Directory with the LDAP provider.
Set objGroup2 = GetObject("LDAP://cn= HR PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup3 = GetObject("LDAP://cn= IT PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup4 = GetObject("LDAP://cn= Eng PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup5 = GetObject("LDAP://cn= Maint PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup6 = GetObject("LDAP://cn=Material PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup7 = GetObject("LDAP://cn= Micro PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup8 = GetObject("LDAP://cn= QS PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup9 = GetObject("LDAP://cn= ProdRel PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup10 = GetObject("LDAP://cn= Techtran PC,ou=GI PC's,ou=GI,dc=app,dc=com")
Set objGroup11 = GetObject("LDAP://cn= Val PC,ou=GI PC's,ou=GI,dc=app,dc=com")

' Add a printer connection if the computer is a member of the group.
If objGroup2.IsMember(objComputer.AdsPath) Then
  objNetwork.AddWindowsPrinterConnection "\\sledc01\HR_C"
Elseif objGroup3.IsMember(objComputer.AdsPath) Then
  objNetwork.AddWindowsPrinterConnection "\\sledc01\MIS_laser"
*************************************************************************************
 
 
Post #: 1
 
 RE: Binding to OU in active directory - 7/20/2005 7:20:03 AM   
  bkhsms

 

Posts: 7
Score: 0
Joined: 7/8/2005
Status: offline
You could assign the print groups and map the appropriate printers:

'===================================================================
'Calls the Sub that will enumerate all of the user's groups and map the appropriate printer
'===================================================================
Call GetGroups()

Wscript.Quit
'================================================================
Sub GetGroups()
On Error Resume Next
adsPath = "WinNT://[domain]/" & strUser & ",user"
Set adsObject = GetObject(adsPath)
For Each grp in adsObject.Groups
Select Case grp.Name
 Case "[group name]"
  Call subexample()  
  End Select
Next
End Sub
'============================================================
'
Sub subexample()
Set objnetwork = CreateObject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection "\\[print server]\[print share]"
objNetwork.SetDefaultPrinter "\\[print server]\[print share]"
End Sub
'============================================================

(in reply to jraisor)
 
 
Post #: 2
 
 RE: Binding to OU in active directory - 7/21/2005 1:07:52 AM   
  jraisor

 

Posts: 39
Score: 0
Joined: 4/29/2005
From:
Status: offline
I'd really like to get away from groups and use OU's though. It doesn't make sense management wise to put a PC in a OU then put it in a group also. If i can just put them in a OU and then the script knows to look and see what OU the PC is a part of and map a printer that way.

(in reply to jraisor)
 
 
Post #: 3
 
 RE: Binding to OU in active directory - 7/21/2005 11:33:16 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
quote:

Set objGroup2 = GetObject("LDAP://cn= HR PC,ou=GI PC's,ou=GI,dc=app,dc=com")


this is just a guess, I've run into this problem with using shell objects that send command strings with spaces in them, but not like yours where its running vbscript the whole time, but try changing the above (or any of your OU paths statements) as a test to this:
Set objGroup2 = GetObject(chr(34) & "LDAP://cn= HR PC,ou=GI PC's,ou=GI,dc=app,dc=com" & chr(34))

The chr(34) construct is used in place of double quotes where you enclose strings that have spaces in them. since your ou names have spaces, this might fix the problem. Or it might not! Let me know if it does or does not work...

(in reply to jraisor)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Binding to OU in active directory Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts