Wednesday, February 8, 2012

PLINK PLINK! - SSH commands over Powershell

Have you ever wanted to automate SSH commands using powershell? PLINK is the way to do it.  On Powershell script, you can use plink.exe command to pass commands to SSH session.  This opens the door to many possibilities.  Most IT server manufacturers use SSH sessions to manage the hardware via SSH command line. 
I am familiar with HP server devices.  On HP servers, you can use SSH command line to connect to iLO and mount CD images via HTTP.   You can use this technique to automate your ESX host server firmware update or even build ESX host server from customized CD ISO.

Example:
Scenario: I am a server administrator that wants to update firmware on 12 ESX host servers in the cluster.  I want to fully automate the update process with Powershell/PowerCLI script.  I do not want any VM downtime.  I do not want endless mouse clicks...

Requirements:
  1. HP licensed iLO and IP address
  2. Fully automated DRS cluster
  3. PLINK.EXE ver 0.60_q1.129
  4. Webserver with ISO image configured with correct MIME type

Solution:

New HP firmware update DVDs are automated by default.  You can take advantage it to automate the process
  1. Get hosts in the cluster and use ForEach loop to put the server in maintenance mode one at a time.
  2. Use the plink command in the script to mount the firmware update ISO image on the ESX host.
  3. Reboot ESX host and Firmware DVD will kick in to automatically boot from the ISO.  It will update the firmware automatically.
  4. When ESX host comes back from disconnected status, take it out of maintenance mode and put next server in to maintenance mode.
  5. Rinse and repeat and you will have hands free firmware update automated script.
 So, how do you use the PLINK command to connect the ILO CD?

2 comments:

  1. $plink = plink -ssh Administrator@$ILOIP -pw $PSWD -auto_store_key_in_cache "set /map1/oemhp_vm1/cddr1 oemhp_boot=once"

    As I understand:
    1. -ssh Administrator@$ILOIP - who and where you connect;
    2. -pw $PSWD - your password;
    3. -auto_store_key_in_cache - what this?
    4. "set /map1/oemhp_vm1/cddr1 oemhp_boot=once" - command that you send;

    So you want to say, that it's automate connection!?
    What about question for all servers that we will try to connect: 'save key in cache?' ?

    I try it and get: " plink: unknown option "-auto_store_key_in_cache" "

    ReplyDelete
  2. Hi.

    1. Administrator account that has rights to iLO and $ILOIP is IP address of iLO device.
    2. correct
    3. If you are connecting to HP iLO from your client for the first time, it automatically stores your key so that you don't get prompted while running script.
    4. correct.

    You need to have specific putty version made by Quest for it to work. Requirment #3 shows you the version. You can easily get it from googling it.

    Requirements:
    HP licensed iLO and IP address
    Fully automated DRS cluster
    PLINK.EXE ver 0.60_q1.129
    Webserver with ISO image configured with correct MIME type

    I hope it helps.

    ReplyDelete