Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
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 transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now