Automation

 View Only
  • 1.  Execute Service Console Commands from Powershell

    Posted Feb 18, 2009 01:53 PM

    Hi all,

    I am using esXpress as my backup / restore system and I've been putting together a powershell script to rebuild and reconfigure my managment servers. I am wondering if there is a way to call the execution of the restore process via powershell.

    esXpress runs on the service console and the commands to restore or backup are run from the service console.

    Any help would be apreciated.

    Best Regards,

    Alasdair..............



  • 2.  RE: Execute Service Console Commands from Powershell

    Posted Feb 18, 2009 02:26 PM

    Hi,

    With the script below, using plink (putty addon), and changing the $remotecommand variable to your service console command line, it should do the job

    $User = <ESX-useraccount>

    $Pswd = <ESX-useraccount-password>

    $Computer = <ESX-hostname>

    $plink = <plink-path>

    $plinkoptions = " -v -batch -pw $Pswd"

    $remoteCommand = <service console command line>

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

    $msg = Invoke-Expression -command $command

    Regards



  • 3.  RE: Execute Service Console Commands from Powershell

    Posted Feb 18, 2009 02:45 PM

    As my scripting skills are pretty basic, can you please verify that the following looks right (as in did I put " in the right places. Thanks

    $User = "root"

    $Pswd = "password"

    $Computer = "sc-gold-mgmt1.vmqaiq.com"

    $plink = "c:\Program Files\Plink\plink.exe"

    $plinkoptions = " -v -batch -pw $Pswd"

    $remoteCommand = "phd-mass restore"

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

    $msg = Invoke-Expression -command $command



  • 4.  RE: Execute Service Console Commands from Powershell
    Best Answer

    Posted Feb 18, 2009 02:53 PM

    it looks good, add a $msg if you wanna display the result of the remote command, as below:

    $User = "root"

    $Pswd = "password"

    $Computer = "sc-gold-mgmt1.vmqaiq.com"

    $plink = "c:\Program Files\Plink\plink.exe"

    $plinkoptions = " -v -batch -pw $Pswd"

    $remoteCommand = "phd-mass restore"

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

    $msg = Invoke-Expression -command $command

    $msg



  • 5.  RE: Execute Service Console Commands from Powershell

    Posted Feb 18, 2009 03:02 PM

    Thanks for the assistance



  • 6.  RE: Execute Service Console Commands from Powershell

    Posted Feb 19, 2009 04:35 PM

    Joel did some really cool stuff here: http://huddledmasses.org/scriptable-ssh-from-powershell/






    [PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator

    Author of the upcoming book: Managing VMware Infrastructure with PowerShell

    Co-Host, PowerScripting Podcast (http://powerscripting.net)

    Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org



  • 7.  RE: Execute Service Console Commands from Powershell

    Posted Feb 20, 2009 11:23 AM

    When I run the script, I get the following error

    Disconnected: User aborted at host key verification

    At :line:104 char:18

    + c:\plink\plink.exe <<<< -v -batch -pw VMWare35 root@sc-gold-mgmt1.vmqaiq.com phd-mass restore

    I assume that this is some sort or server side encrytion key request similar to an sshClient request when going from host to host. Is there a way of automatically answering yes and getting it to connect?

    Thanks in advance for any help....



  • 8.  RE: Execute Service Console Commands from Powershell

    Posted Feb 20, 2009 11:28 AM

    my workaround for this, is to first run putty against the ESX, to get the ssh key stored , not as good as I 'd like to, but for now, I only got this solution



  • 9.  RE: Execute Service Console Commands from Powershell

    Posted Feb 20, 2009 11:48 AM

    I had already putty'd into this host a few times to check the config so not sure if that is the problem. I might just have to get MIS to run this as a manual process



  • 10.  RE: Execute Service Console Commands from Powershell

    Posted Feb 20, 2009 06:49 PM

    The manual way to prevent this err is to putty to the server first. Check your registry, you'll see an entry was created there. If you want to automate it, start here:

    § ATLLAPHROTTENBE {~} Get-ItemProperty hkcu:\software\simontatham\putty\sshhostkeys
    
    
    PSPath                       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\software\s
                                   imontatham\putty\sshhostkeys
    PSParentPath                 : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\software\s
                                   imontatham\putty
    PSChildName                  : sshhostkeys
    PSDrive                      : HKCU
    PSProvider                   : Microsoft.PowerShell.Core\Registry
    rsa2@22:phatlesx02           : 0x23,0x91882dfb914d74b62777c36ca9f8621d349ab8fbf4aa0f45d40e817fb
                                   1076328d084355ce03dac7fd9cc15b98d101ecfd934d1cf6465ee6afc0e858df
                                   f92ba7efa1845acd637ba6c6ee752d787dbef6417d3dd446be75290535553b4e
                                   89ee836da0594bea80f44c115d79b619bd775c812e00144c68d5269b81ab4654
                                   7230f6d407764ee6db64a5cd8bbefeba85e4e9edbb2be396876cbbe46d51db58






    [PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator

    Author of the upcoming book: Managing VMware Infrastructure with PowerShell

    Co-Host, PowerScripting Podcast (http://powerscripting.net)

    Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org