Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a Default printer depending an group Membership 3

Status
Not open for further replies.

NTman2000

MIS
Sep 26, 2006
15
GB
I have cobbled to gether this script to allow me to automatically use 2003 AD (we have Win2k PC's) to map the default printer based on membership of 4 distribution groups
1st Floor User, 2ndFloor User etc

' New Logon script
On Error Resume Next

'4 initial object creation
Dim objNetwork, objGroup , UserObj
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
DomainString = "Company.co.uk"
UserString = WSHNetwork.UserName

set objNetwork = WScript.createObject("WScript.Network")
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'14 Welcome Message
Dim strDomain, strUser
strDomain = ObjNetwork.UserDomain
strUser = ObjNetwork.UserName

MsgBox "Welcome to the " & strDomain & " Network, " & strUser & "!"

'21 Drive Mapping

objNetwork.MapNetworkDrive "G:", "\\Servername\Data1"
objNetwork.MapNetworkDrive "H:", "\\Servername\Accounts"
objNetwork.MapNetworkDrive "I:", "\\Servername\Documents"
objNetwork.MapNetworkDrive "J:", "\\Servername\Personnel"
objNetwork.MapNetworkDrive "K:", "\\Servername\Trescray Utils"
objNetwork.MapNetworkDrive "L:", "\\Servername\Electrical"
objNetwork.MapNetworkDrive "M:", "\\Servername\Archive"
objNetwork.MapNetworkDrive "N:", "\\Servername\Fuji"
objNetwork.MapNetworkDrive "O:", "\\Servername\Homedirs\" & strUser
objNetwork.MapNetworkDrive "P:", "\\Servername\Apps"
objNetwork.MapNetworkDrive "T:", "\\Servername\TestResults"
objNetwork.MapNetworkDrive "V:", "\\Servername\Fiber"
objNetwork.MapNetworkDrive "X:", "\\Servername\Fluor"
objNetwork.MapNetworkDrive "Z:", "\\Servername\Admin Documentation"

'38 Printer Mapping

objNetwork.AddWindowsPrinterConnection "\\Servername\First Floor C450", "Konica Minolta C450 PCL"
objNetwork.AddWindowsPrinterConnection "\\Servername2\Second Floor C450", "Konica Minolta C450 PCL"

objNetwork.AddWindowsPrinterConnection "\\Servername2\First Floor C450", "Konica Minolta C450 PCL"
objNetwork.AddWindowsPrinterConnection "\\Servername\2nd Floor C450", "Konica Minolta C450 PCL"

objNetwork.AddWindowsPrinterConnection "\\Servername\First Floor - Laserjet 2200dn", "HP Laserjet 2200 Series PCL"
objNetwork.AddWindowsPrinterConnection "\\Servername2\First Floor - Laserjet 2200dn", "HP Laserjet 2200 Series PCL"

objNetwork.AddWindowsPrinterConnection "\\Servername\Second Floor - Laserjet 4050", "HP Laserjet 4050 Series PCL"
objNetwork.AddWindowsPrinterConnection "\\Servername2\Second Floor - LaserJet 4050", "HP Laserjet 4050 Series PCL"

objNetwork.AddWindowsPrinterConnection "\\Servername\StoresLJ3200", "HP Laserjet 4M"
objNetwork.AddWindowsPrinterConnection "\\Servername2\Stores Department - LaserJet 3200", "HP Laserjet 4M"

'55 Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups

Select Case GroupObj.Name
'59 Check for group memberships and take needed action
Case "1stFloor User"
objNetwork.SetDefaultPrinter "\\Servername\First Floor C450"
Case "2ndFloor User"
objNetwork.SetDefaultPrinter "\\Servername\Second Floor C450"
Case "3rdFloor User"
objNetwork.SetDefaultPrinter "\\Servername\Second Floor C450"
Case "CAD User"
objNetwork.AddWindowsPrinterConnection "\\Servername\CAD Department - DesignJet 800", "HP DesignJet 800 42 by HP"
objNetwork.AddWindowsPrinterConnection "\\Servername2\CAD Department - DesignJet 800", "HP DesignJet 800 42 by HP"

End Select

Next

'74 Synchronizes the time with Main AD Server our NTP Server


The drives are mapped the printers added But I cannot get teh default printer section lines 55 -73 to select a group from AD by which to decide what floor they are on

Can anyody see what I have missed please ?
 
It was a boring friday morning and you were struggling. I didn't start writing VBScript until a little over a year ago, and it's probably the most useful thing I've picked up in the last couple of years. I hope that this starts you in the same direction.


PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Thanks VERY much for this thread!!!

I had to give a couple of stars out because this solves a problem I have with 2 application support groups.

My primary difficulty is going to be adapting this to account for [red]66 different branches[/red] each having their own printers that will need to be mapped.

Is it possible to move the Select Case to an external file for manageabilbity and script size??



Thanks

John Fuhrman
Titan Global Services
 
For my own personal script, I use the OU that contains the computer account. So that anyone sitting down at that computer gets a set of local printers. For my laptop users I use the current IP subnet to determine which printers they get.

I find it easier to track where computers are than people.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
In my case that doesn't work because everyone coming into the 26 server TS DMZ appears to come from the same location, the firewall.

So my thaught is to rap the Select Case statement in a Sub and make a call to the sub. (Only with a whole lot more Cases!)

Something like this... I hope.
[thumbsup]

Code:
Public Sub MapPrinters(UserString)

[green]'Now check for group memberships and select the correct Case/[green]
strCounter = [red]0[/red] [green]' Initialize counter[/green]
For Each GroupObj In UserObj.Groups
    WScript.Echo UCase(GroupObj.Name) [green]' (Insert echo command for troubleshooting)[/green]

    Select Case UCase(GroupObj.Name) [green]' Convert to Upper Case for consistency[/green]
    
    [green]'Check for group memberships and take needed action[/green]

        Case [red]"025"[/red]
            If strCounter > 0 Then
                WScript.Echo [red]"User is member of multiple banks"[/red]
                Exit For [green]' Causes For...Next loop to end
            Else
                strCounter = strCounter + [red]1[/red] ' Increment counter for next loop[/green]
            End If
            objNetwork.AddWindowsPrinterConnection [red]"\\LXOLCDPRN01\025 Tammy"[/red]
            objNetwork.AddWindowsPrinterConnection [red]"\\LXOLCDPRN01\025johnny"[/red]

Next 
End sub



Thanks

John Fuhrman
Titan Global Services
 
That should work. You just need to decide whether or not users can be members of multiple groups.

I agree though.. TS / Citrix is a whole different beast when you're trying to get the correct printers to users.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top