Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I comeā€¦
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

864 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