#157584 - 2006-02-22 12:24 AM
Weird Results with @ERROR
|
thepip3r
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
|
|
|
|
#157588 - 2006-02-22 01:48 AM
Re: Weird Results with @ERROR
|
thepip3r
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|