PowerCLI

 View Only
Expand all | Collapse all

vmexe HP files execution with PowerCLI

  • 1.  vmexe HP files execution with PowerCLI

    Posted Jun 08, 2018 02:55 PM

    At the end I'm submitting a new thread as I saw that old thread was not moved to the top after the update.

    I created a script to upload the file CPxxxx.vmexe successfully to all involved ESXi hosts. Then I'm running this but it produces no result:

    1. $vmhost = Get-VMHost xxxxxxxxxxxxxxxxxx 
    2.  
    3. # Login credentials to SSH each host. It will convert the string from secure to plain text for plink 
    4. $user = Read-Host "ESXi Host SSH User" 
    5. $rootpword = Read-Host "ESXi Host SSH Password" -AsSecureString 
    6. $rootbstr = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($rootpword) 
    7. $rootpword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($rootbstr) 
    8.  
    9. # The "echo y" command automatically accepts the key for plink. 
    10.   echo y | C:\Users\xxxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword exit | Out-Null 
    11.  
    12. #execute patching 
    13. C:\Users\xxxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch "chmod +x /tmp/CP035395.vmexe" 
    14. start-process "cmd.exe" "/c echo y | C:\Users\xxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch /tmp/CP035395.vmexe" 
    15.  
    16. sleep -Seconds 60 
    17.  
    18. $VMhost | Restart-VMHost -Confirm:$false | Out-Null

    the host gets rebooted but patch is not applied. Is there a way to successfully execute these kind of files with PowerCLI? Executing those commands from within a ssh session works fine.



  • 2.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 08, 2018 04:52 PM

    If you run those plink.exe lines from a CMD box, do they work? Or do they come back with an error?



  • 3.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 08:20 AM

    Hello Luc, yes they do work. I don't want to do extra manual work by ssh to each host... :smileyconfused:



  • 4.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 09:15 AM

    Why is there a difference in the call to plink.exe in your script?

    One is done via Start-Process, any particular reason why?



  • 5.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 09:57 AM

    for the simple reason that so I can get a visual confirmation of the execution. Just that. However I just got a confirmation that even the first line to change permission is not working. If I run it from PowerCLI then into a ssh session I'm not able to successfully run a simple ./CPXXXXX.vmexe --help command. It gives me Permission denied. If I run the chmod command from a ssh session all ok. I'm using root account in all tries.



  • 6.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 12:36 PM

    Do you have sudo activated on that Linux box?

    if yes, could it be the definition in /etc/sudoers?

    Can you check what you have running in your sessions (both ssh and plink.exe) by executing a 'ps'?
    Is there a difference?



  • 7.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 01:26 PM

    no sudo activated on any host. they can be managed only by root account.

    I can see the output of ps with both ssh and plink. Line by line when I get to:

    C:\Users\xxxxx\Documents\VI-Tools\powerCLI\tested\ESXi\plink.exe -ssh $vmhost -l $user -pw $rootpword -batch "chmod +x /tmp/CP035395.vmexe"

    I get:

    chmod: /tmp/CP035395.vmexe: No such file or directory

    and if I provide plink with a cd /tmp/ before the line above the result is the same. I'm lost...



  • 8.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 01:43 PM

    Did you already do a 'pwd' before the other commands?
    Just to know where you get in.



  • 9.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 02:41 PM

    I cleared the environment from all attempts. Now it returns

    /

    and the chown works (I'm able to manipulate the file even in ssh). However I get the cmd window flashing but the file does not flash the system. I'm afraid that these type of files don't work well in this context... or maybe this file in particular...



  • 10.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 03:33 PM

    I had a closer look at that patch, did you also copy the other files over (CP035395.xml and CP035395.vmfile)?



  • 11.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 03:37 PM

    yes, I did. In fact from ssh I can patch the hosts successfully.



  • 12.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 11, 2018 05:07 PM

    It might be that this binary doesn't read the stdin as one would expect.
    You do get a prompt when you start the binary in a ssh session?

    Can you pipe (echo 'y' |) the answer ('y' I assume) to the binary in a ssh session?



  • 13.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 12, 2018 07:25 AM

    I do get a prompt in ssh, and when I pipe echo 'y' | before the line it proceeds correctly without prompting... I give up :smileyconfused:



  • 14.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 12, 2018 07:39 AM

    Unfortunately I don't have a HP box to try it out :smileysad:



  • 15.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 12, 2018 08:55 AM

    thanks anyway for your time!



  • 16.  RE: vmexe HP files execution with PowerCLI

    Posted Jun 18, 2018 12:27 PM

    Hello!

    Can you try this:

    Create a cmds.txt with this content (without the "----" of course :smileywink:):

    -------------------------------------------------

    cd /tmp

    chmod a=rwx CP035395*

    ./CP035395.vmexe -h

    -------------------------------------------------

    And then this PS Script:

    -------------------------------------------------

    $esx_admin = "root"

    $esx_pass = "password"

    $esx_host = "ESXi IP/FQDN"

    $exe_plink = "plink.exe"

    $cmds_plink = "cmds.txt"

    $cmd_arg = "/c echo n | $exe_plink -ssh $esx_host -l $esx_admin -pw $esx_pass -m $cmds_plink"

    Start-Process "cmd" -ArgumentList $cmd_arg -Wait -RedirectStandardOutput 1juhu.log -RedirectStandardError 2err.log

    ----------------------------------------------

    The last line in the "cmds.txt" only prints the help of the vmexe which you can see in the "1juhu.log" - something like: "OS Version found  [6.5.0]..."

    In the 2err.log are all errors. In the case of "-h" there is always this line:

    ./hpsetup: [-h] | [-d[<file>]] | | [--source=<dir> | [-s] [-f] [-r] [-e] [-g]

    If you like to flash change the last line in the cmds.txt from

    ./CP035395.vmexe -h

    to

    ./CP035395.vmexe -s -r

    -s = Silent, no User Interaction

    -r = Reboot

    Hope this helps.

    Robert



  • 17.  RE: vmexe HP files execution with PowerCLI

    Posted Aug 14, 2018 01:26 PM

    many thanks! I moved to a different department and I can't try it out, however I'll keep the script.. you never know!! Cheers!