I'm doing some work in a school, and one of the things they've asked me is to solve the printing issue. Basically, PC's downstairs want to be able to print to the downstairs printer, with the upstairs printer as fallback, and the upstairs PC's want the upstairs printer with the downstairs as the fallback.
So, I have this script.
Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName
arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1)
Set objNetwork = CreateObject("WScript.Network")
'=========================================================================
'STEP 1 - Remove any NETWORK printers (NOT Local Printers)
'=========================================================================
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections
For i = 0 to Printers.Count - 1 Step 2
If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
End IF
Next
'=========================================================================
'STEP 2 - Connect Printers based on COMPUTER OU membership
'=========================================================================
Select Case strComputerOU
Case "Downstairs"
objNetwork.AddWindowsPrinterConnection "\\BISDC01\Central"
objNetwork.AddWindowsPrinterConnection "\\BISDC01\BlueBase"
objNetwork.SetDefaultPrinter "\\BISDC01\Central"
Case "Upstairs"
objNetwork.AddWindowsPrinterConnection "\\BISDC01\Central"
objNetwork.AddWindowsPrinterConnection "\\BISDC01\BlueBase"
objNetwork.SetDefaultPrinter "\\BISDC01\BlueBase"
End Select
As you can see, the server is called BISDC01, and the printers are called Central and BlueBase
The cases for upstairs and downstairs are correct. The bit I'm stuck with it is the path to the OU's.
The path is
bhi.local \ School Computers \ Upstairs
bhi.local \ School Computers \ Downstairs
How do I reference this in the script, as just having upstairs and downstairs cases means I'd have to move the OU's to the root of AD.
Also for my laptops I'm going to need to do something similar except instead of being computer based, I need to make it user based.
Why not try instead of checking for the OU they're in add the PC's to a domain group and use VB to check which group they're in, likewise with the users. We do something similar but for citrix users, the group the user is in dictates which printer they get as a default but they also get all other printers in that office but its done via citrix in built policies so I can't help with any VB for you.
Because the users move between PC's. The downstairs ones are an ICT suite, and classrooms.
When they go up a year, they may move upstairs.
The PC's themselves are static, and I thought this would be a neat solution.
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
Set objADSysInfo = CreateObject("ADSystemInfo")
strComputerName = objADSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputerName)
strOUName = objComputer.DistinguishedName
strOUs = Split(strOUName, ",")
strOU = Split(strOUs(1), "=")
If strOU = "Upstairs" Then
'map the upstairs printer
'map the downstairs printer
Else
'map the downstairs printer
'map the upstairs printer
End If
does that help at all?
Would that point to the correct nestled OU though?
you might have to msgbox the strOU out to prove the point, but it looks like the dn it bring back is something like pcname, ou,ou,ou,domain,suffix
so yeah, it should do.