Page 1 of 1 1
Topic Options
#157584 - 2006-02-22 12:24 AM Weird Results with @ERROR
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Ok, we have a computer naming convention that our IT guys out in each office are supposed to follow and don't. Well our current leadership wants to crack down on the offenders so I'm writing a script to give us a list of computers in AD that don't match the proposed convention. It started out with my conditionals working great until I tried to strip off the front 5 characters of the computer name and then ASCAN() those front five to see if they're what they're supposed to be but my $var that was supposed to return the substr() results, returned nothing. So I started echoing @ERROR and right after my SubStr() command, @SERROR reports "Next without For!" and @ERROR returns no numeric problem. BUT, if i comment out my SubStr() line, the script runs fine. I looked over my past scripts and I'm pretty sure I'm using SubStr() correctly to get the first five chars. Can anyone see a problem?? Thank you in advance.

Code:
Break On

If Len($day) = 1
$day = '0'+$day
Endif

$day = @MDAYNO
$Computers = GetObject("WinNT://n00b.com")
$Computers.filter = "Computer",""
$OutputFile = 'Bad Computer Names ('+@YEAR+' '+SubStr(@MONTH,1,3)+' '+$day+').csv'
$x = 0

$org = "aew","emdg","eamds","emsg","eces",
"econs","ecs","elrs","esfs","esvs",
"emxg","eamxs","emxs","amog","eog",
"efs","eoss","amu","eas"

If Exist(@ScriptDir + '\' + $OutputFile)
Del @ScriptDir + '\' + $OutputFile
Endif

If Open(1,@ScriptDir +"\"+ $OutputFile,5) = 0
for each $Computer in $Computers
If Instr($Computer.name,'-')
$cArr = Split($computer.name,"-")
If Ubound($cArr) <= 1 AND Ubound($cArr) > 2
$ = WriteLine(1,$Computer.name + @CRLF)
$x = $x + 1
Else
$ = WriteLine(1,$Computer.name + @CRLF)
Endif
$fFive = SubStr($Computer.name,0,4)
If @ERROR <> 0 "Error "+@ERROR+": "+@SERROR
;? $fFive
; If Ascan($org,$five) = -1
Else
$ = WriteLine(1,$Computer.name + @CRLF)
$x = $x + 1
Endif
next
Else
? "Error "+@ERROR+": "+@SERROR
Endif

$ = Close(1)

? 'End: '+$x
get $


Top
#157585 - 2006-02-22 12:36 AM Re: Weird Results with @ERROR
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If Ubound($cArr) <= 1 AND Ubound($cArr) > 2

How can UBound be BOTH <=1 AND >2 ????

You populate $fFive but then check $five.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#157586 - 2006-02-22 12:39 AM Re: Weird Results with @ERROR
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Also it looks like you have missing EndIf.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#157587 - 2006-02-22 12:54 AM Re: Weird Results with @ERROR
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Bah you're right on two accounts, Les. I see that my Ubound() conditional is jacked up BUT this line, "; If Ascan($org,$five) = -1" is trivial because it's commented out. I'm not running it yet because I can't even get $fFive to populate with the first five characters. I know that because when I ? $fFive, it returns nothing so then I threw in the @ERROR/@SERROR check and it tells me the error I specified in the first post of this thread, "Next without For!"
Top
#157588 - 2006-02-22 01:48 AM Re: Weird Results with @ERROR
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Nm... rewrote that portion a different way to get around the problem. This is what ended up working...

Code:
Break On

If Len($day) = 1
$day = '0'+$day
Endif

$day = @MDAYNO
$Computers = GetObject("WinNT://n00b")
$Computers.filter = "Computer",""
$OutputFile = 'Bad Computer Names ('+@YEAR+' '+SubStr(@MONTH,1,3)+' '+$day+').csv'
$x = 0

$org = "aew","emdg","eamds","emsg","eces",
"econs","ecs","elrs","esfs","esvs",
"emxg","eamxs","emxs","amog","eog",
"efs","eoss","amu","eas"

If Exist(@ScriptDir + '\' + $OutputFile)
Del @ScriptDir + '\' + $OutputFile
Endif

If Open(1,@ScriptDir +"\"+ $OutputFile,5) = 0
for each $Computer in $Computers
If Instr($Computer.name,'-')
$cArr = Split($computer.name,"-")
If Ubound($cArr) <> 2
$ = WriteLine(1,$Computer.name+',not enough or too many hyphens' + @CRLF)
$x = $x + 1
Else
If Ascan($org,$cArr[0]) = -1
$ = WriteLine(1,$Computer.name+',incorrect first element' + @CRLF)
Endif
Endif

Else
$ = WriteLine(1,$Computer.name + @CRLF)
$x = $x + 1
Endif
next
Else
? "Error "+@ERROR+": "+@SERROR
Endif

$ = Close(1)



Thanx for the help though Les.

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.11 seconds in which 0.06 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