Solved

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

Posted on 2007-11-16
3
1,007 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
  • 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Synchronize a new Active Directory domain with an existing Office 365 tenant
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

773 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