Link to home
Create AccountLog in
VMware

VMware

--

Questions

--

Followers

Top Experts

Avatar of jmachado81
jmachado81

Enable Copy/Paste on ESXi Host via CLI
I am looking to enable copy/paste on an ESXi host via powershell/powercli to complete my script.  I have upgraded to PowerCLI 6.3 and installed PowerShell 5.0 (in hopes this will get me SSH ability).   I have tried SSH-Sessions, http://pwrshell.net/module-ssh-powershell/, and Posh-SSH module.  I'd like to avoid any licensed/buy now modules, so i can share with colleagues without having a licensing concern.

This is the KB article for enabling it.  
https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1026437

==============================================================
If i SSH into a host (using SecureCRT or Putty) and run this I am able to get this completed.
cp /etc/vmware/config /etc/vmware/config.bak
echo >> /etc/vmware/config
echo vmx.fullpath = "/bin/vmx" >> /etc/vmware/config
echo isolation.tools.copy.disable="FALSE" >> /etc/vmware/config
echo isolation.tools.paste.disable="FALSE" >> /etc/vmware/config
exit
==============================================================
I was able to get the closest with Posh-SSH, however that module becomes confused when I enter quotes within quotes.
$command1="Invoke-SSHCommand -index 0 -Command `"echo vmx.fullpath = `"/bin/vmx`" >> /etc/vmware/config`""
$command2="-index 0 -Command `"echo isolation.tools.copy.disable=`"FALSE`" >> /etc/vmware/config`""
$command3="Invoke-SSHCommand -index 0 -Command `"echo isolation.tools.paste.disable=`"FALSE`" >> /etc/vmware/config`""

Invoke-SSHCommand -index 0 -Command "cp /etc/vmware/config /etc/vmware/config.bak"
Invoke-SSHCommand -index 0 -Command "echo >> /etc/vmware/config"
$command1    #this appears to simply put the output on the screen rather than running the command.
Invoke-SSHCommand $command2     #can't interpret the variable as part of the command
$command3
==============================================================

Is there another way I can go about this or is this a piece that must be completed using an SSH Client.  I'm even open to the powershell opening PuTty, connecting, running commands then exiting back to powershell...but that is beyond me.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)Andrew Hancock (VMware vExpert PRO / EE Fellow/British Beekeeper)🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of jmachado81jmachado81

ASKER

I added this to my powershell script:
#====================================================================#
#   HOST - Enable Copy/Paste                                         #
#====================================================================#
Write-Host "-- Execute Batch File " -foregroundcolor green
#---------------------------------------------------------------------#
Start-Process "cmd.exe" "/c C:\Scripts\VMware\Host-CopyPaste.bat"
sleep -Seconds 10
#---------------------------------------------------------------------#

Then I modified script so there  is only a prompt for hostname, but could easily add one for passwords for different environments.  This will auto accept the ssh key.

@echo off
set /p new_host="Enter HostName "

echo yes | "C:\Program Files (x86)\PuTTY\plink.exe" -l root -pw password %new_host% "cp /etc/vmware/config /etc/vmware/config.bak"

"C:\Program Files (x86)\PuTTY\plink.exe" -l root -pw password %new_host% "echo " " >> /etc/vmware/config

"C:\Program Files (x86)\PuTTY\plink.exe" -l root -pw password %new_host% "echo "vmx.fullpath = /bin/vmx"  >> /etc/vmware/config

"C:\Program Files (x86)\PuTTY\plink.exe" -l root -pw password %new_host% "echo isolation.tools.copy.disable="FALSE" >> /etc/vmware/config

"C:\Program Files (x86)\PuTTY\plink.exe" -l root -pw password %new_host% "echo isolation.tools.paste.disable="FALSE" >> /etc/vmware/config

Is there any other known ways or SSH Modules to complete this task solely within PowerShell/PowerCLI?

So you want to do this ONLY in PowerShell?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


This is a good workaround but it also introduces more variables for a user running the script to worry about and more things that could go wrong.  Not that I don't appreciate your work but if there is a possibility it can be performed without those variables I would be interested.

there are no PowerCLI cmdlets that allow editing of files on the host.

seems a bit over the top to wrap it in PowerCLI/Powershell, you could use SSH keys, and perform SSH password less authentication.

you'll will need to use a password, that's a given with plink.

Not sure why the added complication of wrapping it in additional powershell, what's the benefit, other than another layer /

Most of us just use plink, in a batch file or cmd file.

We weren't able to get this task completed all within PowerShell/PowerCli, but with Andrew's help we were able to minimize the user interaction to enable this feature using a batch file run from powershell.

This script assumes that plink is installed in a specific directory and the batch file is also in a specific directory.

Thanks Andrew!

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


VMware

VMware

--

Questions

--

Followers

Top Experts

VMware, a software company founded in 1998, was one of the first commercially successful companies to offer x86 virtualization. The storage company EMC purchased VMware in 1994. Dell Technologies acquired EMC in 2016. VMware’s parent company is now Dell Technologies. VMware has many software products that run on desktops, Microsoft Windows, Linux, and macOS, which allows the virtualizing of the x86 architecture. Its enterprise software hypervisor for servers, VMware vSphere Hypervisor (ESXi), is a bare-metal hypervisor that runs directly on the server hardware and does not require an additional underlying operating system.