Solved

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

Posted on 2013-05-09
4
688 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 21

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 21

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

21 Experts available now in Live!

Get 1:1 Help Now