#205534 - 2012-08-04 05:21 AM
Re: Printers Based on OU
[Re: cjutting]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
What are you having a problem with?
This should give you the OU of the local computer (unable to test)...
$computer = CreateObject("ADSystemInfo").ComputerName
$objComputer = GetObject("LDAP://"+$computer)
$OU = Split(Split($objComputer.Parent,",")[0],"=")[1] You can then just check against that.
http://blogs.technet.com/b/heyscriptingg...belongs-to.aspx
Edited by ShaneEP (2012-08-04 05:25 AM)
|
|
Top
|
|
|
|
#205536 - 2012-08-04 05:26 PM
Re: Printers Based on OU
[Re: cjutting]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Well the code I posted above should return the first OU that the computer is in, and save it in the $OU variable. I compressed it into one line below and added an example of an IF check.
$OU = Split(Split(GetObject("LDAP://"+CreateObject("ADSystemInfo").ComputerName).Parent,",")[0],"=")[1]
If $OU = "OUName1"
$nul = AddPrinterConnection("\\Server\Printer1")
$nul = AddPrinterConnection("\\Server\Printer2")
Endif
If $OU = "OUName2"
$nul = AddPrinterConnection("\\Server\Printer3")
$nul = AddPrinterConnection("\\Server\Printer4")
Endif
Edited by ShaneEP (2012-08-04 05:32 PM)
|
|
Top
|
|
|
|
#205537 - 2012-08-04 05:42 PM
Re: Printers Based on OU
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Or, if you would rather get the last portion of the OU tree you could use something like this...
$OU = GetObject("LDAP://"+CreateObject("ADSystemInfo").ComputerName).Parent
$OU = Split(Right($OU,-InStrRev($OU,"OU=")-2),",")[0]
If $OU = "OUName1"
$nul = AddPrinterConnection("\\Server\Printer1")
$nul = AddPrinterConnection("\\Server\Printer2")
Endif
If $OU = "OUName2"
$nul = AddPrinterConnection("\\Server\Printer3")
$nul = AddPrinterConnection("\\Server\Printer4")
Endif
|
|
Top
|
|
|
|
#205540 - 2012-08-04 07:38 PM
Re: Printers Based on OU
[Re: cjutting]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
That should work just as well. Something like...
$OU = GetObject("LDAP://"+CreateObject("ADSystemInfo").ComputerName).Parent
If Instr($OU,"Terminal Servers") AND InStr($OU,"Headquarters")
;Do Stuff...
Endif
Good luck.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 793 anonymous users online.
|
|
|