Solved

Vbscript to map printers by computer group names using 'case' 2008 domain

Posted on 2013-05-09
4
699 Views
Last Modified: 2013-05-23
Have severan computers in and OU and they are members of group AB_Printers

Need vbs script to map printers using the computer group name in ADDS 2008
(yes I know I can use GPO....but I am asking for vbs) I know hot to do it for users, but need syntax to do it for computer group name using

user example : need correct syntax for computer name object
UserString = WshNetwork.UserName
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

For Each GroupObj In UserObj.Groups
    Select Case UCase(GroupObj.Name)
        Case "AB_Printers"
0
Comment
Question by:BigBadWolf_000
  • 2
4 Comments
 
LVL 22

Expert Comment

by:yo_bee
ID: 39154321
Why not use GPP and leverage Item Level Targeting to deploy your printers.

Here is an article I wrote that can may help.

http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/A_11321-Deploying-Printers-using-Group-Policy-Preferences.html
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 39154328
Hi, this script should work.

Regards,

Rob.

Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")

Dim objWinntComp
Set objWinntComp = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.ComputerName & ",computer")
MsgBox "WinNT://" & objNetwork.UserDomain & "/" & objNetwork.ComputerName & ",computer"

Dim strGroupToCheck
strGroupToCheck = "AB_Printers"

If IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = True Then
	MsgBox "You are a member of " & strGroupToCheck
ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = False Then
	MsgBox "You are NOT a member of " & strGroupToCheck
	WScript.Quit
ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntComp, strGroupToCheck) = "Error" Then
	MsgBox "There was no group found called " & strGroupToCheck
	WScript.Quit
End If	

Function IsMemberOfGroup(strUserDomain, objComp, strGroup) 'the user is a member of a specified group
	IsMemberOfGroup = False
	Dim objGroup
	On Error Resume Next
	Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
	If Err.Number Then
		IsMemberOfGroup = "Error"
	Else
		IsMemberOfGroup = objGroup.IsMember(objComp.ADsPath & "$")
	End If
End Function

Open in new window

0
 
LVL 14

Author Closing Comment

by:BigBadWolf_000
ID: 39191098
Wanted a solution with "case" ....thanks however, the "computername" object helped me resolve my Duh! moment :D
0
 
LVL 22

Expert Comment

by:yo_bee
ID: 39192111
@Wolf.

Did you look at my suggestion? From what I see that you are looking to accomplish you have more control with greater ease using GPP.

Please let me know if you even considered it.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This article runs through the process of deploying a single EXE application selectively to a group of user.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

838 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