Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

831 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