Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Telnet and PowerShell

885 views
Skip to first unread message

Daren Daigle

unread,
Jul 13, 2007, 2:08:55 PM7/13/07
to
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


Marco Shaw

unread,
Jul 13, 2007, 2:42:16 PM7/13/07
to

> 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

Jason

unread,
Jul 13, 2007, 4:33:50 PM7/13/07
to
> 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
------------------------------------------------------

he...@hotmail.co.uk

unread,
Jul 13, 2007, 4:47:08 PM7/13/07
to

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

Hal Rottenberg

unread,
Jul 13, 2007, 5:02:37 PM7/13/07
to
On Jul 13, 4:47 pm, he...@hotmail.co.uk wrote:
> 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


0 new messages