#207797 - 2013-09-23 11:41 PM
Printers Based on OU (Again, Maybe INI File)
|
cjutting
Fresh Scripter
Registered: 2010-02-05
Posts: 40
Loc: IA
|
Hey Guys,
A while ago I posted up this little number looking to add printers based on OUs. http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Main=27580&Number=205533#Post205533
Well I'm finally getting around to it and running into a bit of a snag and wondering if I should actually take another direction in total.
This code is terrible, it's just in testing phases and I'll wind up cleaning it up.
;If Instr($OU,"Terminal Servers") AND InStr($OU,"Headquarters")
;Do Stuff...
;Endif
;****************************************************************
; Declare Variables Here:
call "@ldrive\udf\alludf.kix"
If @ONWOW64 = 1
$printserver = "skm-print3"
else
$printserver = "skm-print1"
EndIf
$printserver1 = "skm-print1"
$printserver2 = "skm-print2"
$printserver3 = "skm-print3"
;******************************************************************
; Some Quick Formalities:
If Not @LOGONMODE
Break on
EndIf
? @FULLNAME + ": Please wait while your printers are being added...."
$OU = GetObject("LDAP://"+CreateObject("ADSystemInfo").ComputerName).Parent
;Can uncomment this for testing OU Settings:
? "$OU"
;Can uncomment this for testing print server settings:
? "$printserver"
select
case instr ($OU,"Business Office") and instr ($OU,"Computers") and instr ($OU,"Insert Facility Here")
? "Business Office"
case instr ($OU,"Education") and instr ($OU,"Computers") and instr ($OU,"Insert Facility Here")
? "Education"
case instr ($OU,"ER") and instr ($OU,"Computers") and instr ($OU,"Insert Facility Here")
? "ER"
case instr ($OU,"Training Room") and instr ($OU,"Computers") and instr ($OU,"Insert Facility Here")
? "Training Room"
case instr ($OU,"Specility Clinic") and instr ($OU,"Computers") and instr ($OU,"Insert Facility Here")
? "Spec Clinic"
case instr ($OU,"Insert Facility Here IT") and instr ($OU,"Computers")
? "IT Printers"
;printer_map("$printserver",'IT-PR2')
;printer_map("$printserver",'IT-PR3')
endselect
sleep 10
;Map Printers
function printer_map($server,$printer)
AddPrinterConnection("\\$server\$printer")
error_check(@ERROR,@SERROR,"couldnt add $printer from $server")
endfunction
;Map Default Printers
function default_printer_map($server,$printer)
SetDefaultPrinter("\\$server\$printer")
error_check(@ERROR,@SERROR,"couldnt make $printer default from $server")
endfunction
;Error Checking For Script
function error_check($errnum,$error,$message)
If @ERROR<>0
$txtlog = "\\skm-file01\logonlogs$\pcprinters.txt"
$sFile = "\\skm-file01\logonlogs$\"
open(1,$sFile)
$rc = WriteLog($txtlog,@WKSTA+" "+Join(Split(@IPADDRESS0),"")+" "+ @USERID + " "+ @DATE + " " + @TIME + " Error# $errnum $error $message" + Chr(13) + Chr(10))
EndIf
endfunction
I'm sure it's just syntax, but when I run the script my desktop belongs to the Facility IT Computers (which is the last case in this statement). Instead it's getting caught by the ER Group. Others are getting caught as well.
Any thought on the syntax from the original post.
Also does anybody have any good (and instructions for id10ts) ini file for printer examples? I'm wondering if that is a better way to go long term.
Thanks for the help and thoughts
|
|
Top
|
|
|
|
#207798 - 2013-09-24 12:12 AM
Re: Printers Based on OU (Again, Maybe INI File)
[Re: cjutting]
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I have a logon script that does the same thing, printers based off of OU membership.
I use the incontainer() UFD. Dont forget this udf needs the TranslateName() too.
Here is just a SMALL snip of our 35 site logon script that maps printers.
;Use the OU to dertermin what Site for printers and icons.
$Offices = 'ou=Offices,ou=STD,dc=elements,DC=std'
$dfw = ',ou=dfw,' +$Offices
$abrams = 'ou=abrams' +$dfw
$berry = 'ou=berry' +$dfw
Select
;------------Dallas------------
case incontainer($abrams,'user')[0]
? 'Abrams'
$ = addprinterconnection('\\st-ps01\Copier Abrams')
$ = setdefaultprinter('\\st-ps01\Copier Abrams')
case incontainer($berry,'user')[0]
? 'Berry'
$ = addprinterconnection('\\st-ps01\Copier Berry')
$ = setdefaultprinter('\\st-ps01\Copier Berry')
endselect
|
|
Top
|
|
|
|
#207801 - 2013-09-24 04:34 AM
Re: Printers Based on OU (Again, Maybe INI File)
[Re: Glenn Barnas]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Technically it's working as it should, since the string "Insert Facility Here IT" contains the string "ER" (in the word here). Maybe changing the case statements to something like the below (just added ='s to the beginning) will do the trick...Since it will not evaluate true if a portion happens to appear in the middle.
select
case instr ($OU,"=Business Office") and instr ($OU,"=Computers") and instr ($OU,"=Insert Facility Here")
? "Business Office"
case instr ($OU,"=Education") and instr ($OU,"=Computers") and instr ($OU,"=Insert Facility Here")
? "Education"
case instr ($OU,"=ER") and instr ($OU,"=Computers") and instr ($OU,"=Insert Facility Here")
? "ER"
case instr ($OU,"=Training Room") and instr ($OU,"=Computers") and instr ($OU,"=Insert Facility Here")
? "Training Room"
case instr ($OU,"=Specility Clinic") and instr ($OU,"=Computers") and instr ($OU,"=Insert Facility Here")
? "Spec Clinic"
case instr ($OU,"=Insert Facility Here IT") and instr ($OU,"=Computers")
? "IT Printers"
;printer_map("$printserver",'IT-PR2')
;printer_map("$printserver",'IT-PR3')
endselect
|
|
Top
|
|
|
|
#207802 - 2013-09-24 01:47 PM
Re: Printers Based on OU (Again, Maybe INI File)
[Re: ShaneEP]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
Just at first glance, I don't understand the InStr logic.. an AD Object can only be a member of one OU, so why all the AND logic? If you're going to match OUs using Case statements, create one for each exact match - or, as Shane pointed out - add delimiters to your queries. I wrap OU lookup with a leading "=" and trailing "," to avoid unwanted substring matches.
So - for the ER, match on "OU=ER," And "OU=Facility". Forget Computers in the case statements.. that's required by all matches so filter it earlier with a simple "If".If InStr($OU, '=Computers,')
Select
Case InStr($OU, '=Business Office,') And InStr($OU, '=Facility,')
Case InStr($OU, '=ER,') And InStr($OU, '=Facility,')
EndSelect
EndIf The idea is to keep the logic as simple as possible.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|