austinb
Contributor
Contributor

Windows Telnet Commands

Jump to solution

Can someone provide an example of how to execute telnet commands against a windows vm from Orchestrator. I've tried multiple options and I can't get it to work. The connection is working, I just can't get any commands to execute. I'm assuming my syntax is incorrect. I would really appreciate any help someone can provide! Thanks in advance.

var myTelnetClient = new TelnetClient();

var ipAddress = System.getModule("com.vmware.lcm.vim3").getTokenIpAddress(token);

//Connect

myTelnetClient.connect(ipAddress);

//Issue Command

myTelnetClient.sendString("mkdir c:\temp\lcm");

//Disconnect

myTelnetClient.disconnect();

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal

Hi Austin,

I managed to have some code working here. I'm not sure everything is needed but...

var myTelnetClient = new TelnetClient();

var ipAddress = "myServer"

//Connect

myTelnetClient.connect(ipAddress);

//login

sendString("myDomain
administrator");

sendString("myP@ssw0rd");

//Issue Command

sendString("md c:
temp
test");

//Disconnect

myTelnetClient.disconnect();

function sendString(msg) {

myTelnetClient.sendString(msg);

myTelnetClient.waitForData(1000);

System.log(myTelnetClient.receiveAsString());

}

First, Rob was right. You need to log-in (as our Telnet client is not able to use your current Windows session credentials).

I use a function, sendString, so each time I send a string, I also wait a short time (1000 is for 1 second) and show the text returned if any. Don't bother for the "null" returned, it just means there is no message for us right now. This way, you can debug your script easily.

Next, note that you have to use the username or domain\username for to log in. As we are in Javascript, you have to escape the \ in the string. That's why I have wrote
each time I need \. This is valid for the path too.

Finally, the windows command line tool to create a directory is md. I'm not sure if mkdir is working in telnet.

Note for those who are interested. You can use powershell too by this way. Just start powershell just after the login.

View solution in original post

0 Kudos
5 Replies
admin
Immortal
Immortal

Hi,

I suspect you need to 'login' with a username and password.

Cheers,

Rob.

admin
Immortal
Immortal

Hi Austin,

I managed to have some code working here. I'm not sure everything is needed but...

var myTelnetClient = new TelnetClient();

var ipAddress = "myServer"

//Connect

myTelnetClient.connect(ipAddress);

//login

sendString("myDomain
administrator");

sendString("myP@ssw0rd");

//Issue Command

sendString("md c:
temp
test");

//Disconnect

myTelnetClient.disconnect();

function sendString(msg) {

myTelnetClient.sendString(msg);

myTelnetClient.waitForData(1000);

System.log(myTelnetClient.receiveAsString());

}

First, Rob was right. You need to log-in (as our Telnet client is not able to use your current Windows session credentials).

I use a function, sendString, so each time I send a string, I also wait a short time (1000 is for 1 second) and show the text returned if any. Don't bother for the "null" returned, it just means there is no message for us right now. This way, you can debug your script easily.

Next, note that you have to use the username or domain\username for to log in. As we are in Javascript, you have to escape the \ in the string. That's why I have wrote
each time I need \. This is valid for the path too.

Finally, the windows command line tool to create a directory is md. I'm not sure if mkdir is working in telnet.

Note for those who are interested. You can use powershell too by this way. Just start powershell just after the login.

View solution in original post

0 Kudos
austinb
Contributor
Contributor

Cedric,

Thank you for such a complete response. I was able to get this working using your example. I didn't realize I needed to pass in my login credentials, I thought it would pick it up from the service account running Orchestrator.

Thanks Again!

0 Kudos
admin
Immortal
Immortal

Cedric,

I am very interested in your comments on this being a way to run powershell scripts as well. I have a lot of powershell scripts that I have written, and now I want to enable\or execute these scripts via orchestrator. Is there away to have javacript call powershell scripts or telnet to a windows machine that is sort of a script repository the best option?

Thanks,

Joe

0 Kudos
tschoergez
Leadership
Leadership

Hi Joe,

maybe this is also a solution for you:

http://www.powershellinside.com/powershell/ssh/

Watch also:

http://communities.vmware.com/thread/271425?tstart=0

cheers,

joerg

0 Kudos