Solved

Login VBScript for Mapping Printers based on Computer's Security Group

Posted on 2007-11-16
3
1,014 Views
Last Modified: 2011-10-03
I've been banging my head at this all day. Someone please help!

I am trying to do exactly as the title states. I want to push printers based on the Computer's group membership. I keep receiving the same error and I have no idea why.

"The directory property cannot be found in the cache."
Code: 8000500D

Here's what I got so far:

Please help!

'=====================================================================
'
' This script pulls down the computer name and group membership and applies
' the proper printers to that security group.
' The Group name next to the Case, must match the group name in the domain exactly!
' The groups must be Global groups in the domain, not domain local groups.
'=====================================================================
' Code to prevent an errors from showing to user
'=====================================================================
 
 
'=====================================================================
' Binding Shell and Network Objects
'=====================================================================
set objnet = CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
 
'=====================================================================
' Setting Variables for later use.
'=====================================================================
 
strComputerDN = objSysInfo.COMPUTERNAME
 
MSGBOX strComputerDN
 
'=====================================================================
' Binding objcomp to pull computer information
'=====================================================================
Set objcomp = GetObject("LDAP://" & strComputerDN)
 
'=====================================================================
' This pulls the group information for the computer
'=====================================================================
strGroups = objComp.GetEx("member of")
 
For Each Group In strGroups
 
Set ThisGroup = GetObject("LDAP://" & Group)
	GroupName = ThisGroup.CN
 
	Select Case GroupName
'=====================================================================
' Each entry after 'Case' must match global group exactly!
'=====================================================================
		Case "1st Floor - NE"
'=====================================================================
' Code for adding a department share shortcut to user's desktop
'=====================================================================			
  				
 			objnet.AddWindowsPrinterConnection "\\dc01\casesum5"
 
		Case "1st Floor - NW"
			
			objnet.AddWindowsPrinterConnection "\\dc01\casesum3"	
	
End Select
 
Next

Open in new window

0
Comment
Question by:DJS_IT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 20301720
It's failing on line 34, as the "member of" part isn't working.  Here's another way to do it:


'Array of DNs of the groups to check against
arrGroups = Array("cn=1st Floor - NE,ou=site1,dc=yourcomain,dc=local",_
	"cn=1st Floor - NE,ou=site1,dc=yourcomain,dc=local")
 
For Each strGroup in arrGroups
    Set objGroup = GetObject ("LDAP://" & strGroup)
        For Each objComputer in objGroup.Members
            If objComputer.Class = "computer" And objComputer.DistinguishedName = strComputerDN Then
                strGroupName = strGroup
            End If
        Next
Next
 
Select Case strGroupName
etc.

Open in new window

0
 

Author Comment

by:DJS_IT
ID: 20312914
You'll have to forgive me, I am very very early on in learning vbscript. Can you explain how that script is working and what I would need to edit on it to add a printer mapping by group?

Again, I'm sorry for making you spell it out for me, but I am a complete beginner.

Thanks!
0
 
LVL 38

Assisted Solution

by:Shift-3
Shift-3 earned 500 total points
ID: 20313429
> arrGroups = Array( ...
arrGroups is an array containing the Distinguished Name of each group you want to check the computer's membership against.  The underscore (_) is used to break a command across multiple lines.

> For Each strGroup in arrGroups
This command loops through the array of groups and executes actions on each one.

> Set objGroup = GetObject ("LDAP://" & strGroup)
This queries Active Directory for information on the selected group.

> For Each objComputer in objGroup.Members
This gets a list of all members of the specified group and executes actions on each one.

> If objComputer.Class = "computer" And objComputer.DistinguishedName = strComputerDN Then
This filters the list of members so that only computer objects are selected and then it looks to see if any have the same Distinguished Name as the local computer.

> strGroupName = strGroup
If any of the computer DNs match then it sets the value of the strGroupName variable to the Distinguished Name of the group being searched.

> Select Case strGroupName
This goes through a list of group DNs and if any of them match the value of strGroupName then drive mapping commands will be executed.

You already had some Case statements which would map network printers.  You just need to modify them to check by each printer's Distinguished Name instead of Common Name (e.g. Case "cn=1st Floor - NE,ou=site1,dc=yourcomain,dc=local" instead of Case "1st Floor - NE".

You might want to look over these articles which explain similar scripts:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1210.mspx
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul07/hey0727.mspx
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
A hard and fast method for reducing Active Directory Administrators members.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question