jeff_eisenberg
(Fresh Scripter)
2009-06-18 01:18 AM
jumping sections of a script / excluding workstations

I konw there is a much better way to do this but just don't have the experience to know. I'd like to make an exclusion list so I don't run certain parts of my script on specified workstations

IF NOT @WKSTA = "Workstation1" OR "Workstation2" OR "Workstation3" OR "etc"
RUN SOME COMMAND
ENDIF


AllenAdministrator
(KiX Supporter)
2009-06-18 01:56 AM
Re: jumping sections of a script / excluding workstations

One way...
See ComputerInGroup() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84539

 Code:
If ComputerInGroup("SomeGroupName",@domain)
  ;do stuff
Endif


jeff_eisenberg
(Fresh Scripter)
2009-06-18 02:21 AM
Re: jumping sections of a script / excluding workstations

What if I want to include the computer names within the script?

AllenAdministrator
(KiX Supporter)
2009-06-18 02:31 AM
Re: jumping sections of a script / excluding workstations

You asked for a better way... \:\)

jeff_eisenberg
(Fresh Scripter)
2009-06-18 02:43 AM
Re: jumping sections of a script / excluding workstations

So I tried the syntax below but it only seems to register the first entry "Workstation1". Is there some reason the script would not pay attention to the following entries after "Workstation1"? In other words, it runs the command if it is run on Workstation2, 3, etc.

IF NOT @WKSTA = "Workstation1" OR "Workstation2" OR "Workstation3" OR "etc"
RUN SOME COMMAND
ENDIF


AllenAdministrator
(KiX Supporter)
2009-06-18 02:45 AM
Re: jumping sections of a script / excluding workstations

Okay... maybe this way then?

Create an INI file and use EnumINI() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=135385

untested:
 Code:
$excludedcomputers=EnumINI("File.ini")
if ascan($excludedcomputers,@wksta)=-1
  ;not in the excluded list, so do stuff
else
  ;found the excluded computer, so skip this section
endif


AllenAdministrator
(KiX Supporter)
2009-06-18 02:52 AM
Re: jumping sections of a script / excluding workstations

The problem with what you are doing is, you are creating a mess and don't realize it.

what you are asking for is something like...

if @wksta="Workstation1" or @wksta="Workstation2" or @wksta="Workstation3"

...but when you start sticking Not in front of those with OR... the results are going to be something other than what you are expecting, not to mention hard to follow.


AllenAdministrator
(KiX Supporter)
2009-06-18 03:03 AM
Re: jumping sections of a script / excluding workstations

I think this will work... not tested.

 Code:
if not(@wksta="Workstation1" or @wksta="Workstation2" or @wksta="Workstation3")
  ;do stuff
endif


I hate this kind of code... my eyes cross and then I question what I did... if its right... Anyone else care to jump in here.


jeff_eisenberg
(Fresh Scripter)
2009-06-18 06:43 AM
Re: jumping sections of a script / excluding workstations

Thanks Allen,

As bad as it is, at least I see where my syntax was wrong.

JEff.


Richard H.Administrator
(KiX Supporter)
2009-06-18 10:51 AM
Re: jumping sections of a script / excluding workstations

If you don't want to use external (ini) file then a simpler and more manageable way of implementing exclusion lists is with arrays:
 Code:
$aExclusionList_1=Split("Workstation1,Workstation2,Workstation3",",")

If 1+AScan($aExclusionList_1,@WKSTA)
	"Workstation "+@WKSTA+" is in exclusion list"+@CRLF
Else
	"Workstation "+@WKSTA+" is not in exclusion list"+@CRLF
EndIf


BradV
(Seasoned Scripter)
2009-06-18 12:11 PM
Re: jumping sections of a script / excluding workstations

I think Allen's first idea was the best. By creating a group and putting the computers you want to exclude in it, you just need to set up your script once. Later if you need to add another system, or remove one, you don't have to change your script. Rather, you just add or remove a computer from the group. I think it is much cleaner and easier to maintain.

Regards,

Brad