Page 1 of 1 1
Topic Options
#138165 - 2005-04-19 05:34 PM IF PC is a member of an OU THEN...
pat_smith1969 Offline
Fresh Scripter

Registered: 2005-04-19
Posts: 18
We run a fairly simple KIX script, doing nothing more than

IF INGROUP("group") THEN
USE g: \\someserver\someshare
End IF

This has worked well for us for a while but now I wish to do something a bit more complicated.

I want to install a piece of software on every machine at logon. The software is sart enough to check to see if it is already installed and skip if it is. SO that is not an issue (it is the ALtiris client).

The problem is we dont necessarly want this to run on any machine that is in our Servers OU.

Idealy I would do something like

If Machine <> OU=Servers,DC=TIGR,DC=ORG THEN
\\server\share\package.exe
End IF

Has anyone done anything like this before? That is has anyone performed an action based on the Machines' OU membership?

Any Help whoud be appriecieated. I have done a search but found nothing like what I need.

Top
#138166 - 2005-04-19 05:56 PM Re: IF PC is a member of an OU THEN...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Check out the InContainer() function. You will also need TranslateName()

Code:

Break On

if not InContainer('OU=Servers,DC=TIGR,DC=ORG', 'Computer')[0]
shell '\\server\share\package.exe'
endif

Function InContainer ($Container, $NameType)
Dim $Container, $CurrentContainer, $NameType, $Name1, $Name2

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
$CurrentContainer = substr($Name2[0], instr($Name2[0], ",")+1)
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 ($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


Top
#138167 - 2005-04-19 09:12 PM Re: IF PC is a member of an OU THEN...
pat_smith1969 Offline
Fresh Scripter

Registered: 2005-04-19
Posts: 18
Thank You VERY MUCH!!!
Couple questions...
I understand the IF/End IF statement but what is the [0] at the end of line 2 of your script?

I am adding another condition to the IF statement and am wondering how the [0] plays in...

I will do something like

Break On
if not InContainer('OU=Servers,OU=Machines,DC=TIGR,DC=ORG', 'Computer')[0] AND not INCOntainer('OU=Domain Controllers,DC=TIGR,DC=ORG', 'Computer')[0] THEN
shell '\\server\share\package.exe'
endif

Also I need to exclude Particular PC names

Top
#138168 - 2005-04-19 09:20 PM Re: IF PC is a member of an OU THEN...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The [0] is the first element of the returned array. What you propose makes no sence because a computer cannot be in both OUs.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138169 - 2005-04-19 09:21 PM Re: IF PC is a member of an OU THEN...
pat_smith1969 Offline
Fresh Scripter

Registered: 2005-04-19
Posts: 18
Actually this syntax would be more appropriate...

Break On
if not InContainer('OU=Servers,OU=Machines,DC=TIGR,DC=ORG', 'Computer')[0]
IF NOT InContainer('OU=Domain Controllers,DC=TIGR,DC=ORG', 'Computer')[0]
shell '\\server\share\package.exe'
EndIf
endif

The above script works fine... so the questions are...
What does the [0] mean (is it something I need to worry about?
Is there an easy way to exclude particular PC Names.

I will continue to research and post if I figure it out myself.

Top
#138170 - 2005-04-19 09:23 PM Re: IF PC is a member of an OU THEN...
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
Quote:


I understand the IF/End IF statement but what is the [0] at the end of line 2 of your script?

I am adding another condition to the IF statement and am wondering how the [0] plays in...






It is an array

Also watch the UDF library:

InContainer() - Determines if the current account or computer is in a container


Edited by Co (2005-04-19 09:25 PM)
_________________________
Co


Top
#138171 - 2005-04-19 09:25 PM Re: IF PC is a member of an OU THEN...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
InContainer returns an array. If you don't know what an array is, then you should hit up the manual and other resources.

The result of the membership check is contained in the first element of the array, which is Index 0, hence the [0].

Top
#138172 - 2005-04-19 09:26 PM Re: IF PC is a member of an OU THEN...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Did you not read my reply? A computer cannot be in two different OUs!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138173 - 2005-04-19 09:28 PM Re: IF PC is a member of an OU THEN...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Les, i think you're missing the "Not"s.
Top
#138174 - 2005-04-19 09:33 PM Re: IF PC is a member of an OU THEN...
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
Yeah
_________________________
Co


Top
#138175 - 2005-04-19 09:40 PM Re: IF PC is a member of an OU THEN...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
NOTS! What kind of twisted logic is that?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138176 - 2005-04-19 11:02 PM Re: IF PC is a member of an OU THEN...
pat_smith1969 Offline
Fresh Scripter

Registered: 2005-04-19
Posts: 18
I think I was posting while you posted so I didnt see your reply until AFTER I posted my reply...

My current Syntax works GREAT.. Thank you.

Break On
if not InContainer('OU=Servers,OU=Machines,DC=TIGR,DC=ORG', 'Computer')[0]
If Not Incontainer('OU=Domain Controllers,DC=TIGR,DC=ORG', 'Computer')[0]
Shell \\altiris\Express\pat.bat
EndIF
endif
Function InContainer ($Container, $NameType)
Dim $Container, $CurrentContainer, $NameType, $Name1, $Name2
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
$CurrentContainer = substr($Name2[0], instr($Name2[0], ",")+1)
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 ($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
Thank you for the reply about the [0] I have a VAGUE idea of what an array is and how to use them so your explanation is sufficient, IF I need to konw more I will do the suggested reading. Thanks again.

My last question is ...
Is there an easy way to do a check of the PCNAME and an if statement based on that...

IF PCName <> "PatsPC-xp"

Also most of my programming experience is in the ASP world and I find the lack of a "Then" quite disconcerting

Top
#138177 - 2005-04-19 11:08 PM Re: IF PC is a member of an OU THEN...
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:


My last question is ...
Is there an easy way to do a check of the PCNAME and an if statement based on that...

IF PCName <> "PatsPC-xp"





Sure

Code:

If @WKSTA <> "PatsPC-xp"
your script goes here
Else
?"This is PatsPC-xp!"
EndIf


would do the trick.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

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

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