Link to home
Create AccountLog in
Avatar of bill_lynch
bill_lynchFlag for United States of America

asked on

Map Network printer based on OU

Greetings:
I have the following script:
'  VBScript to map two printers from two servers
'  
'  ******************************
Dim multiPrinter, UNCpath1, UNCpath2
UNCpath1 = "\\cnb06\hptrain"
UNCpath2 = "\\cnb06\trainer"
Set multiPrinter = CreateObject("WScript.Network")
multiPrinter.AddWindowsPrinterConnection UNCpath1
multiprinter.RemovePrinterConnection UNCpath1
multiPrinter.AddWindowsPrinterConnection UNCpath2
multiprinter.SetDefaultPrinter "\\cnb06\trainer"
WScript.Quit
' End of example VBScript

The script works well when I just run it.
However the users that need to run it are not assigned to the OU in which the computers are.
This is a training room.  We have a training room OU that has an OU for the computers in it.
The user objects are in another OU, so when I assign it as a User Group policy, it will not map the printer.  Any suggestions?
Avatar of yehudaha
yehudaha
Flag of Israel image

example from scripting guy

change the the o name in the case statment to your training ou

you can leave one case and edit it like this

Select Case strComputerOU
    Case "training"
        objNetwork.AddWindowsPrinterConnection "\\PrintServer1\ClientPrinter"
end select
Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName

arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1)

Set objNetwork = CreateObject("WScript.Network")

Select Case strComputerOU
    Case "Client"
        objNetwork.AddWindowsPrinterConnection "\\PrintServer1\ClientPrinter"
        objNetwork.SetDefaultPrinter "\\PrintServer1\ClientPrinter"
    Case "Finance"
        objNetwork.AddWindowsPrinterConnection "\\PrintServer2\FinancePrinter"
        objNetwork.SetDefaultPrinter "\\PrintServer2\FinancePrinter"
    Case "Human Resources"
        objNetwork.AddWindowsPrinterConnection "\\PrintServer3\HRPrinter"
        objNetwork.SetDefaultPrinter "\\PrintServer3\HRPrinter"
    Case "Research"
        objNetwork.AddWindowsPrinterConnection "\\PrintServer4\ResearchPrinter"
        objNetwork.SetDefaultPrinter "\\PrintServer4\ResearchPrinter"
    Case Else
        objNetwork.AddWindowsPrinterConnection "\\PrintServer5\GenericPrinter"
        objNetwork.SetDefaultPrinter "\\PrintServer5\GenericPrinter"
End Select

Open in new window

in it wasnt clear the script map base on computer  ou
Avatar of bill_lynch

ASKER

I only have 1 OU that I need to map printers for so this appears to be over kill?

I just want a simple script, I can assign to the OU Training and have all the computers in that OU be assigned the correct printer.
sorry didn't get the tearm over kill :-)

this is a simple script but here a version that will work for you
and if i under stand correct your ou name is "Training".

edit the printer unc to your detailes you can copy the line how much your want to match your printer you want to map:
objNetwork.AddWindowsPrinterConnection "\\PrintServer1\ClientPrinter"

Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName

arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1)

Set objNetwork = CreateObject("WScript.Network")
Select Case strComputerOU
    Case "Training"
        objNetwork.AddWindowsPrinterConnection "\\PrintServer1\ClientPrinter"
        objNetwork.SetDefaultPrinter "\\PrintServer1\ClientPrinter"
end select

Open in new window

OK, I can try this.

What if The OU is a couple of layers down, i.e. \\domain\departments\training in the AD structure.  Will I need to specify that anywhere?  Would I still apply this script to the training OU as a user login script?
Where is this script checking against Active Directory?
ASKER CERTIFIED SOLUTION
Avatar of yehudaha
yehudaha
Flag of Israel image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I decided not to pursue this.