Jump to content

Recommended Posts

Posted

I am soon to rollout a a new shared printer but want it to be applied to the user, this will be shared from our print server. I need a script that will check the user is a member of a group called xnlnelpct.nhs.uk\sg-print-navigo, if they are a member I want them to be mapped with \\nel-prt-01\nagivo.

 

I also want the script to remove any printers but leave any that are called Adobe or another which I think is CutePDF.

 

Can this be done?

 

Or if it cannot be done by a security group can it be done on what OU the user is in?

 

Any examples would be a help, need to start testing this soon and I am not a scripter.

 

Thanks

Posted
I have a set of scripts that look for XXXX-YY-ZZZZ and as long as a printer is named XXXX-PB or PC-ZZZZ it will map it. We apply it at the school level of GPO. (I am at the District level here in the US and we have 100+ schools) I will gladly send them to you but since they are VBS our email will not let me So I would need to do it tonight. Let me know if you would like them.
Posted

Something to let you start (some excerpts from our script)

 

Set objNetwork = CreateObject("WScript.Network")
Set objAllDrives = objNetwork.EnumNetworkDrives
Set objPrinters = objNetwork.EnumPrinterConnections

strADUserName = objNetwork.UserName 
strADComputerName = objNetwork.ComputerName
strADDomain = objNetwork.UserDomain
'Connect to user object in AD
Set objADUserbind = GetObject("WinNT://" & strADDomain & "/" & strADUserName)

'Remove all printers
For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2
   If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
     objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True
   End If
Next

For Each objADGroup In objADUserbind.Groups
   Select Case UCase(objADGroup.Name)
	Case "sg-print-navigo"
		objNetwork.AddWindowsPrinterConnection "\\nel-prt-01\nagivo"
		objNetwork.SetDefaultPrinter "\\nel-prt-01\nagivo"
	End Select
Next

bio..

Posted

How are you runnign the script?

If you are running it as a logon script pushed by GPO you can filter the GPO by security group to eliminate the need for the script to check the group.

Posted

Cheers for the replies, I will have a look when I get time next week.

 

The script is a login script at the minute it is on OU but not ever one will need access hence why adding to a security group and doing it that way.

 

Will look at it when I can sit down on the network and play.

  • 8 months later...
Posted

I have managed to get this script working ok:

 

Set WshNetwork = CreateObject("WScript.Network") 

WshNetwork.AddWindowsPrinterConnection "\\NEL-NAVPRT-01\Mono Printing" 
WshNetwork.AddWindowsPrinterConnection "\\NEL-NAVPRT-01\Colour Printing"

WshNetwork.SetDefaultPrinter "\\NEL-NAVPRT-01\Mono Printing" 

 

I cannot get it to add a printer if a computer is member of certain security group, can anyone help?

Posted
Basically I want a script that if computer object is member of i.e. PRINTER1 then map \\server\printer1, if member of PRINTER2, map \\server\printer2, if that makes sense?
Posted (edited)

You could use the below scripts and just alter them slightly

 

Checking Group Membership in VBScript - CyrusBuilt dot Net

 

Main Code :

 

[color=#008000]'******************************************************************** [/color][color=#008000]'* [/color][color=#008000]'* Function IsGroupMember() [/color][color=#008000]'* Purpose : Determines if the specified object is a member of the [/color][color=#008000]'*               specified group. [/color][color=#008000]'* Input ..: UserOrComputerDN - [string] The distinguished name of [/color][color=#008000]'*                               the user or computer to check. [/color][color=#008000]'*           GroupName        - [string] The name of the group to [/color][color=#008000]'*                               check membership of. [/color][color=#008000]'* Output .: True  - The user is a member. [/color][color=#008000]'*           False - The user is not a member, the group does not [/color][color=#008000]'*                   exist, or the user does not exist. [/color][color=#008000]'* [/color][color=#008000]'******************************************************************** [/color][color=#E56717][b]Function[/b][/color] IsGroupMember([color=#151B8D][b]ByVal[/b][/color] UserOrComputerDN, [color=#151B8D][b]ByVal[/b][/color] GroupName)     [color=#151B8D][b]On[/b][/color] [color=#151B8D][b]Error[/b][/color] [color=#151B8D][b]Resume[/b][/color] [color=#8D38C9][b]Next[/b][/color]     [color=#151B8D][b]Dim[/b][/color] iRet     [color=#151B8D][b]Dim[/b][/color] objUserOrComputer     [color=#151B8D][b]Dim[/b][/color] objGroup     [color=#151B8D][b]Dim[/b][/color] sGroup     [color=#151B8D][b]Dim[/b][/color] colGroups     iRet = [color=#00C2FF][b]False[/b][/color]       [color=#008000]'Bind user or computer AD object. [/color]    [color=#151B8D][b]Set[/b][/color] objUserOrComputer = [color=#E56717][b]GetObject[/b][/color]([color=#800000]"LDAP://"[/color] & UserOrComputerDN)     [color=#8D38C9][b]If[/b][/color] ((Err.Number = 0) [color=#8D38C9][b]And[/b][/color] (IsObject(objUserOrComputer))) [color=#8D38C9][b]Then[/b][/color]         [color=#008000]'Get the collection of groups the object is a member of. [/color]        colGroups = objUserOrComputer.MemberOf         [color=#8D38C9][b]If[/b][/color] ([color=#8D38C9][b]Not[/b][/color] IsEmpty(colGroups)) [color=#8D38C9][b]Then[/b][/color]             [color=#8D38C9][b]If[/b][/color] (TypeName(colGroups) = [color=#800000]"String"[/color]) [color=#8D38C9][b]Then[/b][/color]                 [color=#008000]'User is a member of only one group. [/color]                [color=#151B8D][b]Set[/b][/color] objGroup = [color=#E56717][b]GetObject[/b][/color]([color=#800000]"LDAP://"[/color] & colGroups)                 [color=#8D38C9][b]If[/b][/color] ((Err.Number = 0) [color=#8D38C9][b]And[/b][/color] (IsObject(objGroup))) [color=#8D38C9][b]Then[/b][/color]                     [color=#8D38C9][b]If[/b][/color] (LCase(objGroup.CN) = LCase(GroupName)) [color=#8D38C9][b]Then[/b][/color]                         iRet = [color=#00C2FF][b]True[/b][/color]                     [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]                 [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]             [color=#8D38C9][b]Else[/b][/color]                 [color=#008000]'Object is a member of multiple groups. [/color]                [color=#008000]'Iterate through the groups the user is a member of and see [/color]                [color=#008000]'if any of them match the specified group. [/color]                [color=#8D38C9][b]For[/b][/color] [color=#8D38C9][b]Each[/b][/color] sGroup [color=#8D38C9][b]In[/b][/color] colGroups                     [color=#151B8D][b]Set[/b][/color] objGroup = [color=#E56717][b]GetObject[/b][/color]([color=#800000]"LDAP://"[/color] & sGroup)                     [color=#8D38C9][b]If[/b][/color] ((Err.Number = 0) [color=#8D38C9][b]And[/b][/color] (IsObject(objGroup))) [color=#8D38C9][b]Then[/b][/color]                         [color=#8D38C9][b]If[/b][/color] (LCase(objGroup.CN) = LCase(GroupName)) [color=#8D38C9][b]Then[/b][/color]                             iRet = [color=#00C2FF][b]True[/b][/color]                             [color=#E56717][b]Exit[/b][/color] [color=#8D38C9][b]For[/b][/color]                         [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]                     [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]                 [color=#8D38C9][b]Next[/b][/color]             [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]         [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]     [color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]       [color=#008000]'Dispose objects and return. [/color]    [color=#151B8D][b]Set[/b][/color] objGroup = [color=#00C2FF][b]Nothing[/b][/color]     [color=#151B8D][b]Set[/b][/color] objUserOrComputer = [color=#00C2FF][b]Nothing[/b][/color]     IsGroupMember = iRet [color=#8D38C9][b]End[/b][/color] [color=#E56717][b]Function[/b][/color]

 

Code to call Function to check if the computer is apart of the relevant security group(s) - in your case Printer1, Printer2 etc

 


Set WshNetwork = CreateObject("WScript.Network") 
[color=#151B8D][b]Dim[/b][/color] userDN [color=#151B8D][b]Dim[/b][/color] Printer1, Printer2
Printer1 = [color=#800000]"Printer1"[/color]
Printer2 = "Printer2" 
userDN = [color=#800000]"CN=John Doe,OU=My Division,DC=fabrikam,DC=com"[/color] 
[color=#8D38C9][b]If[/b][/color] IsGroupMember(userDN, Printer1) [color=#8D38C9][b]Then[/b][/color]    
WshNetwork.AddWindowsPrinterConnection "\\Server\Printer1"  [color=#8D38C9][b]
End[/b][/color] [color=#8D38C9][b]If
[/b][/color][color=#8D38C9][b]If[/b][/color] IsGroupMember(userDN, Printer2) [color=#8D38C9][b]Then[/b][/color]    
WshNetwork.AddWindowsPrinterConnection "\\Server\Printer2"  
[color=#8D38C9][b]End[/b][/color] [color=#8D38C9][b]If[/b][/color]
WshNetwork.SetDefaultPrinter "\\Server\PrinterX"

 

Adjust PrinterX for Printer1 or Printer2 depending on which you want setting as default or whatever, also you need to adjust the userDN ( LDAP path ) for your computers OU

Edited by mac_shinobi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...