#138165 - 2005-04-19 05:34 PM
IF PC is a member of an OU THEN...
|
pat_smith1969
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
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
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
|
|
|
|
#138169 - 2005-04-19 09:21 PM
Re: IF PC is a member of an OU THEN...
|
pat_smith1969
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
|
|
|
|
#138173 - 2005-04-19 09:28 PM
Re: IF PC is a member of an OU THEN...
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Les, i think you're missing the "Not"s.
|
|
Top
|
|
|
|
#138176 - 2005-04-19 11:02 PM
Re: IF PC is a member of an OU THEN...
|
pat_smith1969
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|