#116937 - 2004-03-26 11:18 PM
Stripping lines and chars from an array
|
Little_John
Fresh Scripter
Registered: 2004-03-23
Posts: 12
|
Well, from my previous post (regarding finding user names and resolving them to host and IP) I delve deeper into the maddness.
Code:
$=RedirectOutput("error.txt")
$nFndID=insert username here
$nView=WshPipe('net view') If @ERROR Exit @ERROR EndIf For Each $nCPU In $nView Join(Split($nCPU,"\"),"") = $nHost $nHost
$nUser=WshPipe('nbtstat -a' +$nHost+' ""',1) If InStr($nUser, $nFndId) $nfnd=Split($nUser, "") For Each $aFnd In $nfnd If InStr($nfnd, $nFndId) blah, blah, blah...
I know, know...it's a meager start (very meager), but cut me some slack I'm a newbie(thank you very much). So here's what happens...I'm running a 'net view' from a cmd line and putting the output into $nView then I'm creating a variable on the fly called $nCPU (I know, OPTION EXPLICIT ON, but still). What I'm attempting after that is what has me stumpped. I'm trying to remove the "\\" from the front of the computer name and then call that $nHost so I can do an nbtstat -a on it, but it keeps failing. Here's what my error.txt file says...
[not code] Server Name Remark
------------------------------------------------------------------------------- \\ID6042 \\ID6495 The command completed successfully.
0
[/not code] couldn't resist---hehe
It's all that space I don't know what to do with, and the dashes, and why is $nHost = 0.
HELP OH GREAT ONES, FOR I'VE LOST MY WAY. Not really, I've just got no clue what I'm doing. Thanks in advance.
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.
|
|
Top
|
|
|
|
#116938 - 2004-03-26 11:57 PM
Re: Stripping lines and chars from an array
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Well, if you have a string that looks like... \\ID6042 and you want it to look like this... ID6042 you could do this...
Code:
If InStr($nCPU,"\\") $nHost = Split(Split($nCPU," ")[0],"\\")[1] EndIf
|
|
Top
|
|
|
|
#116940 - 2004-03-29 08:15 PM
Re: Stripping lines and chars from an array
|
Little_John
Fresh Scripter
Registered: 2004-03-23
Posts: 12
|
Great, thanks. Will that bypass the first few lines and go straight to the CPU names or do I still need to strip those.
Server Name Remark
------------------------------------------------------------------------------- \\ID6042 \\ID6495
The server name remark line the spaces and the dash line. Do I use a read line to jump to line 5 or whatever, or how would I do it?
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.
|
|
Top
|
|
|
|
#116942 - 2004-03-29 08:20 PM
Re: Stripping lines and chars from an array
|
Little_John
Fresh Scripter
Registered: 2004-03-23
Posts: 12
|
Quote:
Did you try my example within your For...Each...Next loop?
What example. This post or the other?
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.
|
|
Top
|
|
|
|
#116943 - 2004-03-29 08:29 PM
Re: Stripping lines and chars from an array
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
This post.
Better example...
Code:
$nView=WshPipe('net view')
For Each $nCPU In $nView
If InStr($nCPU,"\\")
$nHost = Split(Split($nCPU," ")[0],"\\")[1]
$nHost ?
EndIf
Next
Edited by Chris S. (2004-03-29 08:33 PM)
|
|
Top
|
|
|
|
#116944 - 2004-03-30 03:28 PM
Re: Stripping lines and chars from an array
|
Little_John
Fresh Scripter
Registered: 2004-03-23
Posts: 12
|
Yes, I did add that, but I think I like the this new example better, seems a bit more clear to my befuddled mind. About the other question...will this skip the dashed line and the other b.s. at the top of the text doc, or do I need a readline statement? Sorry to be a pest, but I'm out of the office and only have limited access to the net. Also, being that I'm away from my beloved LAN I'm not able to continue testing. Thanks for your patience.
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.
|
|
Top
|
|
|
|
#116945 - 2004-03-30 03:56 PM
Re: Stripping lines and chars from an array
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I have a few UDFs in the forum to do much of this..
see ReadFile() and FilterArray()
use readfile() to read the file into an array use filterarray() to return lines with '\\' then do a for each loop with elements of the array and then joinsplit them on '\'
|
|
Top
|
|
|
|
#116946 - 2004-03-31 10:21 PM
Re: Stripping lines and chars from an array
|
Little_John
Fresh Scripter
Registered: 2004-03-23
Posts: 12
|
Thanks for all the help folks. I'll try this again when I'm back on my LAN.
Thanks again.
Little John
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|