PowerCLI

 View Only
  • 1.  how to copy and execute bash script on esxi server

    Posted Jun 29, 2018 08:53 PM

    any idea how I can copy a folder with  bash scripts to a local DS and execute on the esxi host?



  • 2.  RE: how to copy and execute bash script on esxi server

    Posted Jun 29, 2018 09:01 PM

    Copying a file to a datastore is simple with Copy-DatastoreItem.

    But running that file as a script will at least require a SSH session to the ESXi node.

    Do you have SSH access?



  • 3.  RE: how to copy and execute bash script on esxi server

    Posted Jun 29, 2018 09:46 PM

    can i copy it to /var or /tmp on the esxi host?

    yes I have ssh access but the script restarts ssh



  • 4.  RE: how to copy and execute bash script on esxi server

    Posted Jun 29, 2018 10:02 PM

    Such a copy would only work over SSH.

    Have a look at the Posh-SSH module.

    There is a good intro at SSH for Windows Powershell



  • 5.  RE: how to copy and execute bash script on esxi server

    Posted Jun 30, 2018 05:28 PM

    any idea how I can copy a local folder to multiple remote local ds?

    I got the commands

    $datastores = get-vmhost host1, host2, host3 | get-datastore  -name local*

    foreach ($ds in $datastores) {

    new-datastoredrive -name test -datastore $ds

    copy-datastoreitem -item "c:\script\sub -destination test: -REcurse

    write-output "yes" | plink $plink $vmhost "root" "xxxxx" "mv /vmfs/volumes/$ds/sub /tmp"

    }

    any idea?



  • 6.  RE: how to copy and execute bash script on esxi server

    Posted Jun 30, 2018 05:44 PM

    Try something like this

    $esxNames = 'esx1','esx2','esx3'

    Get-VMHost -Name $esxNames | Get-Datastore -Name local* | ForEach-Object{

       $ds = $_

       New-DatastoreDrive -Name DS -Datastore $ds

       Copy-DatastoreItem -Item c:\script\sub -Destination "DS:" -Recurse

       Remove-PSDrive -Name DS -Confirm:$false


       Write-Output "yes" | plink $plink $vmhost "root" "xxxxx" "mv /vmfs/volumes/$($ds.Name)/sub /tmp"

    }



  • 7.  RE: how to copy and execute bash script on esxi server

    Posted Jul 01, 2018 01:42 PM

    hi Luc

    getting this error



  • 8.  RE: how to copy and execute bash script on esxi server

    Posted Jul 01, 2018 02:13 PM

    actually getting a different error now



  • 9.  RE: how to copy and execute bash script on esxi server

    Posted Jul 01, 2018 02:45 PM

    now getting differnt error



  • 10.  RE: how to copy and execute bash script on esxi server

    Posted Jul 01, 2018 02:55 PM

    That's a lot of different messages :smileygrin:

    One seems to indicate that the folder/file is not found.

    Did you check that the folder was actually copied, and the folder is there?



  • 11.  RE: how to copy and execute bash script on esxi server

    Posted Jul 01, 2018 07:24 PM

    I am not sure why I am getting this error



  • 12.  RE: how to copy and execute bash script on esxi server

    Posted Jul 01, 2018 07:52 PM

    Looks like plink.exe can not be found in the folders specified in $env:Path.

    Add the PuTTY folder, containing plink.exe to $env:Path.

    Or call plink.exe with the complete path, for example C:\PuTTY\plink.exe