Group:  English: General ยป microsoft.public.windows.powershell
Thread: Telnet and PowerShell

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Telnet and PowerShell
"Daren Daigle" <ddaigle[ at ]bgca.org> 13.07.2007 18:08:55
I am trying to automate a process through powershell to connect via telnet
port to a cisco switch or router. After I do so, log in, have it copy the
running config to a tftp server and disconnect.

I know how to do the steps manually but i would like to automate this as i
have a large number of switches and routers that I want to capture both the
running and startup configs.

I have found a script that makes powershell act like a telnet client, but i
am looking for a way to deal with the telnet data like i would from the old
standard of line by line reading like from a text file.

Any suggestions on how to set up the stream so i can react to and respond
back to the session in say a line by line format (helps for parsing).

Daren Daigle
Boys and Girls Clubs of America


Re: Telnet and PowerShell
Marco Shaw <marco.shaw[ at ]_NO_SPAM_gmail.com> 13.07.2007 18:42:16

[Quoted Text]
> Any suggestions on how to set up the stream so i can react to and respond
> back to the session in say a line by line format (helps for parsing).

I think I followed you up to this last paragraph...

How about this?

63# start-transcript device1.log
Transcript started, output file is device1.log
64# "testing"
testing
65# stop-transcript
Transcript stopped, output file is C:\powershell\device1.log
66# gc device1.log
**********************
Windows PowerShell Transcript Start
Start time: 20070713153851
Username : ALIANT\MA36788
Machine : NB517949 (Microsoft Windows NT 5.1.2600 Service Pack 2)
**********************
Transcript started, output file is device1.log
64# "testing"
testing
65# stop-transcript
**********************
Windows PowerShell Transcript End
End time: 20070713153900
**********************
67#

You can use start-transcript to record everything going in on the
console. Then you might just have to trim the first and last few lines
to get just your config.

Marco
Re: Telnet and PowerShell
"Jason" <nospam[ at ]nospam.com> 13.07.2007 20:33:50
[Quoted Text]
> I have found a script that makes powershell act like a telnet client, but
> i am looking for a way to deal with the telnet data like i would from the
> old standard of line by line reading like from a text file.

Might be overkill, but perhaps the System.Console class has what you need
(see the ReadLine method notes):

http://msdn2.microsoft.com/en-us/library/system.console.aspx

There's also the NetCmdlets from nSoftware, which might have easier-to-use
methods to read telnet output:

http://www.nsoftware.com/powershell/default.aspx


Cheers,
Jason


------------------------------------------------------
PowerShell Training at SANS Conferences
http://www.WindowsPowerShellTraining.com
------------------------------------------------------

Re: Telnet and PowerShell
hecks[ at ]hotmail.co.uk 13.07.2007 20:47:08
On Jul 13, 7:08 pm, "Daren Daigle" <ddai...[ at ]bgca.org> wrote:
[Quoted Text]
> I am trying to automate a process through powershell to connect via telnet
> port to a cisco switch or router. After I do so, log in, have it copy the
> running config to a tftp server and disconnect.
>
> I know how to do the steps manually but i would like to automate this as i
> have a large number of switches and routers that I want to capture both the
> running and startup configs.
>
> I have found a script that makes powershell act like a telnet client, but i
> am looking for a way to deal with the telnet data like i would from the old
> standard of line by line reading like from a text file.
>
> Any suggestions on how to set up the stream so i can react to and respond
> back to the session in say a line by line format (helps for parsing).
>
> Daren Daigle
> Boys and Girls Clubs of America

Lee Holmes' Connect-Computer v2 script is pretty easy to adapt for a
combination of interactive and automated processing in a session (if
that's what you mean):

http://www.leeholmes.com/blog/default,date,2006-12-04.aspx

Scroll down to 29 Nov 2006, 'Scripting Network / TCP Connections in
PowerShell'.

-Hecks

Re: Telnet and PowerShell
Hal Rottenberg <halr9000[ at ]gmail.com> 13.07.2007 21:02:37
On Jul 13, 4:47 pm, he...[ at ]hotmail.co.uk wrote:
[Quoted Text]
> Lee Holmes' Connect-Computer v2 script is pretty easy to adapt for a
> combination of interactive and automated processing in a session (if
> that's what you mean):
>
> http://www.leeholmes.com/blog/default,date,2006-12-04.aspx
>
> Scroll down to 29 Nov 2006, 'Scripting Network / TCP Connections in
> PowerShell'.

Direct link: http://www.leeholmes.com/blog/ScriptingNetworkTCPConnectionsInPowerShell.aspx

OMG, I was working on this problem using connect-computer.ps1 version
1, didn't know about v2! I basically did v1.1 in a very poor way. Oh
well, I learned some things. :)

Read about it here if you like: http://halr9000.com/article/397

-hal
http://halr9000.com


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net