Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1021
  • Last Modified:

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

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
DJS_IT
Asked:
DJS_IT
  • 2
2 Solutions
 
Shift-3Commented:
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
 
DJS_ITAuthor Commented:
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
 
Shift-3Commented:
> 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now