Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapping printers based on computer group membership

Status
Not open for further replies.

alura

Technical User
Jun 23, 2003
28
US
Hi - I am somewhat familiar with VB script, but I am stumped here. I want to rewrite our current login script to map printers based on their computer group membership. I made AD computer groups.

Example: AD computer group "Accounting" contains all the computers in the accounting department.

I found a function online, but it doesnt appear to fully work:

Private Function MemberOf(groupName, className)

dim tmpStr
set adSysInfo = CreateObject("ADsystemInfo")
tmpStr = ""

If uCase(className) = "COMPUTER" Then
set obj = GetObject("LDAP://" & adSysInfo.ComputerName)
Else
set obj = GetObject("LDAP://" & adSysInfo.UserName)
End If

strGroups = UCase(Join(obj.MemberOf))
If InStr(strGroups, uCase(groupName)) Then
MemberOf = True
Else
MemberOf = False
End IF

End Function


And then I call it like this in the script:

If MemberOf("MUNICIPAL","COMPUTER") Then
Call AddPrinter ("GRIMLAW", "POSEIDON", "Municipal")
Call AddPrinter ("GRIMLAW", "HERCULES", "municolor")
Call AddPrinter ("GRIMLAW", "SPHINX", "Perkasie Fax")
Call AddPrinter ("GRIMLAW", "POSEIDON", "Computer Room Copier")
objWshNetwork.SetDefaultPrinter "\\POSEIDON\MUNICIPAL"
End If

But it doesn't seem to work, or works at random... mapping printers that aren't even belonging to that group.

My current login script has a function called InGroup, but it only works for user accounts. Here is the function for that:

Private Function InGroup(strGroup)

On Error Resume Next

InGroup = False
'Search strUserGroups for strGroup
If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True

End Function

Private Sub GetGlobalGroupMembership

On Error Resume Next

Dim objNameSpace
Dim objUser

Const ADS_READONLY_SERVER = 4

Set objNameSpace = GetObject( "WinNT:" )
'Use the OpenDSObject method with the ADS_READONLY_SERVER
'value to grab the "closest" domain controller

'Connect to user object in the domain
Set objUser = objNameSpace.OpenDSObject( _
"WinNT://" & strDomain & "/" & strUserID, "", "", ADS_READONLY_SERVER)
'Process each group
For Each objGroup In objUser.Groups
'Add group name to list
strUserGroups = strUserGroups & objGroup.Name & ","
Next
Set objNameSpace = Nothing

End Sub

Private Sub GetLocalGroupMembership
On Error Resume Next

Dim colGroups 'Collection of groups on the local system
Dim objGroup 'Object reference to individual groups
Dim objUser 'Object reference to individual group member

'Verify system is not Windows 9x or ME
If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
'Connect to local system
Set colGroups = GetObject( "WinNT://" & strWorkstation )
colGroups.Filter = Array( "group" )
'Process each group
For Each objGroup In colGroups
'Process each user in group
For Each objUser in objGroup.Members
'Check if current user belongs to group being processed
If LCase( objUser.Name ) = LCase( strUserID ) Then
'Add group name to list
strUserGroups = strUserGroups & objGroup.Name & ","
End If
Next
Next
Set colGroups = Nothing
End If

End Sub


Any help would be appreciated... Or if someone just has a basic WSH function that will let me do an If then statement based on computer group membership.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top