Remotely run vcenter console commands automated.

I have deployed a vCenter 6.0 host using the automated deployment method which has worked fine, now I want to run some commands to join the vcenter to the domain. I have the commands I need but need a way to run these again the vcenter in an automated way - I have tested the commands by accessing the vcenter console with Putty and running them sequentially which work.

What I need is a way to automate the running of these scripts which is compatible with vcenter 6.0, for vcenter 5.5 I used the WinSCP library to upload and then execute a configuration file which worked fine however this doesnt seem to work for vcenter 6.0.

So the question is how can I remotely access the vCenter 6.0 console and run commands in an automated way - what I really need is a way to run these commands from a C# application. Any ideas?
Blowfelt82Asked:
Who is Participating?
 
Blowfelt82Author Commented:
Managed to solve this. You need to enable the bash shell via a standard SSH connection and then run shell commands by prefixing the bash commands with 'shell {command}'. Changing the BASH shell within the script seems to cause problems with the existing SSH connection.
0
 
Blowfelt82Author Commented:
OK got a bit further, apparently this is because the vcenter defaul host is not configured to bash. This can be configured via the OVFTool deployment by:

--prop:guestinfo.cis.appliance.root.shell="/bin/bash"

Unfortunately I am not using the OVFTool for deployment so this isnt an option for me, although this does work.

Using SSH this can be set manually (I have used Putty to configure this manually but this is not an automated method). I have also tried using the Tamir.SHarpSSH library to connect using the SSH protocol but this does not work. Is there any way I can configure the default shell as part of the deployment. At the moment it is looking like a chicken and egg situation.

shell.set --enabled True
shell
chsh -s "/bin/bash" root

(Credit goes to William Lam for this).
0
 
Blowfelt82Author Commented:
Note:

Connecting with Tamir.SharpSSH gives error:

SshShell Ssh = new SshShell("xxx.xxx.xxx.xxx", "root", "mypassword");
Ssh.Connect()

Open in new window


This returns JSchException was unhandled - Algorithm negotiation failed.

I am not sure what this means but it doesnt sound good.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
gheistCommented:
It means that you use substandard ages old tapir ssh client that does not support 15 years old SSH v2 protocol.
0
 
Blowfelt82Author Commented:
Fair enough, do you know of any freeware ssh libraries I could build into a c# application?
0
 
gheistCommented:
vsphere powercli ?
google code and sourceforge are  good places to search for freeware....
0
 
Blowfelt82Author Commented:
Powercli? Can this be used to set the default root - if so that could do the job? Was reading up on Tamir.SharpSSH and it says it supports SSH-2.
0
 
gheistCommented:
You can set root password from vcenter host profiles. No need to run SSH ever.
0
 
Blowfelt82Author Commented:
The password is set via the deployment json file, it's the setting of the default shell from the appliancesh shell to bash?
0
 
gheistCommented:
Ahh... thats virtual machine template... I thought you manipulate ESXi.
You must use vmware studio to add custom attributes, then it can execute commands to apply them within image.
0
 
Blowfelt82Author Commented:
This solution allows SSH connections to run BASH commands directly as needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.