Page 1 of 2 12>
Topic Options
#151680 - 2005-11-17 01:37 PM IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
Is it possible to use IF on OU, like we use IF ingroup ?
Top
#151681 - 2005-11-17 01:41 PM Re: IF based on Orginzational Unit
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Welcome to the board.

You can't use ingroup to check on OU membership.
However there is a UDF here that can do this task for you.
InContainer() - Determines if the current account or computer is in a container
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#151682 - 2005-11-17 01:46 PM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
Thank you for faaast answaer
Will the syntax be : 'IF INCONTAINER ("OU")'

TR

Top
#151683 - 2005-11-17 01:50 PM Re: IF based on Orginzational Unit
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
The syntax is listed in the commented section (see examples part). Please also read the dependencies section (just above the examples part) cause it requires an extra UDF called TranslateName() and AD aware clients.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#151684 - 2005-11-17 01:54 PM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
I'm sorry, I'm a rookie on kix, what would be the right syntax if I want to check a users OU membership syntax ?
Top
#151685 - 2005-11-17 02:01 PM Re: IF based on Orginzational Unit
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Something like this should do.

You should change this part OU=test,OU=9826,OU=NCS,OU=Machines,DC=us,DC=tycoelectronics,DC=com to match your situation. The user to query is now set to the user the script runs on by the first line of code below.

Code:

$User = @USERID

$rc = InContainer ("OU=test,OU=9826,OU=NCS,OU=Machines,DC=us,DC=tycoelectronics,DC=com", $User)
Select
Case $rc[0]=1 ? "object is a member of the specified container."
Case $rc[0]=2 ? "object is a member of a child container lower in the hierarchy."
Case $rc[0]=0 ? "object is NOT a member of this container or a child of this container."
Case $rc[0]=-1 ? "InContainer() Error - Invalid input for $NameType "
Case $rc[0]=-2 ? "TranslateName() Error"
Case 1 ? "Unknown return code"
EndSelect


;Do NOT midify anything below this line!
;
;FUNCTION InContainer()
Function InContainer ($Container, $NameType)
Dim $CurrentContainer, $Name1, $Name2, $Found, $commaloc

Select
Case $NameType = "Computer" $Name1 = @Domain + "\" + @wksta + "$$"
Case $NameType = "User" $Name1 = @LDomain + "\" + @UserID
Case 1 $Name1 = ""
EndSelect

If $Name1 <> ""
$Name2 = TranslateName (3, "", 3, $Name1, 1)

If $Name2[1] = 0

$Found=0
While $Found=0
$commaloc = InStr($Name2[0], ",")
If $commaloc > 1
If SubStr($Name2[0],$commaloc-1,1) = "\"
$Name2[0] = SubStr($Name2[0], $commaloc+1)
Else
$Found=1
$CurrentContainer = SubStr($Name2[0], $commaloc+1)
EndIf
Else
$Found=1
EndIf
Loop

Select
Case $CurrentContainer=$Container $InContainer = 1, $Name2[1], $Name2[2]
Case InStr($Name2[0], $Container) $InContainer = 2, $Name2[1], $Name2[2]
Case 1 $InContainer = 0, $Name2[1], $Name2[2]
EndSelect
Else
$InContainer = -2, $Name2[1], $Name2[2]
EndIf
Else
$InContainer = -1, 0, ""
EndIf
EndFunction

;FUNCTION TranslateName()
Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)

Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
Dim $NameTranslate, $ReturnName, $Error, $ErrorText

$Error = 0
$ErrorText = ""
$ReturnName = ""
$NameTranslate = CreateObject ("NameTranslate")
$Error = @error
$ErrorText = @serror
If $Error = 0
$NameTranslate.Init ($InitType, $BindName)
$Error = @error
$ErrorText = @serror
If $Error = 0
$NameTranslate.Set ($LookupNameType, $LookupName)
$Error = @error
$ErrorText = @serror
If $Error = 0
$ReturnName = $NameTranslate.Get($ReturnNameType)
$Error = @error
$ErrorText = @serror
EndIf
EndIf
EndIf
$TranslateName = $ReturnName, $Error, $ErrorText
EndFunction



Edited by Mart (2005-11-17 02:03 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#151686 - 2005-11-17 02:06 PM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
Jeez, all this just to check if a user is member of an OU ???
Top
#151687 - 2005-11-17 02:14 PM Re: IF based on Orginzational Unit
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Two functions are included in the code above. One to check if the user is a member and one to convert the name.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#151688 - 2005-11-17 02:46 PM Re: IF based on Orginzational Unit
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Jeez, all this just to check if a user is member of an OU ???




Yes, KiXtart doesn't support the features natively, so it can get a little complicated.

However, for your needs the following might provide all the information that you require:
Code:
$=SetOption("WrapAtEOL","ON")

$oADInfo = CreateObject("ADSystemInfo")
$oADInfo.ComputerName ?
$oADInfo.UserName ?


Top
#151689 - 2005-11-17 03:28 PM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
I was going to use a check on OU, for mapping printers for users in that spesific OU.

ps. I am getting the error code 2 when using setdefaultprinter, any idea ?

This is my script :

IF INGROUP ("Stamsund")
If AddPrinterConnection ("\\aks01\hp4200-stamsund") = 0
? "Added printer connection...."
endif
SetDefaultPrinter("\\aks01\hp4200-stamsund")
? "Set default printer to HP LaserJet 4...."


Edited by Trygve (2005-11-17 04:10 PM)

Top
#151690 - 2005-11-17 03:29 PM Re: IF based on Orginzational Unit
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Is the printer AND the share name the same?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#151691 - 2005-11-17 03:29 PM Re: IF based on Orginzational Unit
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
You should use Addprinterconnection() first
_________________________



Top
#151692 - 2005-11-17 04:11 PM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
yepp. I typed wrong. AddPrinterConnection is first. My problem with that one was wrong printername, when using SetPrinterDefault..
Top
#151693 - 2005-11-17 04:13 PM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
But I really need som good advice for a short script for checking before mapping a printer, with user in a OU, not a group...

Richard H. : Can I use you script for this purpose ?

Top
#151694 - 2005-11-18 09:05 AM Re: IF based on Orginzational Unit
Trygve Offline
Fresh Scripter

Registered: 2005-11-17
Posts: 8
Is there no good tips for using IF with OU check for users, when mapping printers ?
Top
#151695 - 2005-11-18 10:25 AM Re: IF based on Orginzational Unit
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Richard H. : Can I use you script for this purpose ?




Yes. Have you tried it? You should see your user path displayed.

Now you can use something like "InStr()" to check is you are in an OU.

Here is an example which checks if I'm in the IT staff OU:
Code:
$oADInfo = CreateObject("ADSystemInfo")

$sITOU="OU=IT Users,OU=I.T. Teams,OU=Leatherhead Office,OU=Corporate,DC=ACME,DC=com"

If InStr($oADInfo.UserName,$sITOU)
"Yes, I'm in the IT OU"+@CRLF
Else
"No, I'm not IT staff"+@CRLF
EndIf


Top
#151696 - 2005-11-18 01:25 PM Re: IF based on Orginzational Unit
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I think you have already been given the best solution. Use InContainer().

As discussed in a previous thread InContainer always calls TranslateNAme() which can add substatial overhead to the script. A cleaner solution is to use TranslateName() to get the user's OU and then use a modified Incontainer() that only compares strings representations of the OU's DN.

I will post the code after I get to work.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#151697 - 2005-11-18 01:36 PM Re: IF based on Orginzational Unit
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Howard,

What's the issue with using the scriptlet I've just posted?

I'd planned on using it myself in various places so if there is a potential problem I'd like to know about it.

Top
#151698 - 2005-11-18 05:34 PM Re: IF based on Orginzational Unit
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Looks good Richard. I was rushing around and did not spend sufficient time reading your post. You solution is elegantly simple and directly applicable to a single user logging on which satisfies the request.

I think that my solution is more flexible/powerful (shameless plug) from an admin script perspective.

Your solution only seems to identify that the user is somewhere in the OU tree. My solution determine if you are in the OU or a child.


Edited by Howard Bullock (2005-11-18 05:36 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#151699 - 2006-01-24 11:14 PM Re: IF based on Orginzational Unit
flashcash5 Offline
Lurker

Registered: 2006-01-24
Posts: 4
Hi All!
Good to be a member of the board, i've been looking through this forum alot, thanks to everyone for the help so far.

I am hoping to do the same thing Tryvge was trying to do in his last post (with InContainer).
For example if a user is in a certain OU map this printer, drive etc,
if a user is in this other OU do this, that etc..

Was just wondering if you had that sample code you mentioned by any chance please?
Quote:

I will post the code after I get to work.




Just if you have it handy thats all,

Thanks a mill

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.078 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org