VMware Copy Paste Enabler
Something that has annoyed me with VMware when compared to Hyper-V is the fact that Hyper-V lets you paste into the VM console. By default VMware has that disabled but you can manually enable it. Doing that is kind of slow so I wrote a script with PowerCLI to enable copy paste on a VM.
In order to make everything work you’ll need VMware PowerCLI Installed (here’s how to do that)
The script makes the changes that VMware listed here (https://kb.vmware.com/s/article/57122)
The script also checks if the VM is currently running if it is it turns if off then makes the changes and turns it back on.
If the VM is off the script just makes the changes.
I’ve only tested this with VCSA 7.
Before running the script just edit the variable vm_Name
to reflect the name of the VM you want to enable copy paste on. After that it’s just a matter of connecting to VCSA and running the script.
Here’s a link to the script hosted on my GitHub https://github.com/thedxt/VMware#vm-copy-paste-enabler
3 responses to “VMware Copy Paste Enabler”
Hi. thanks for providing this script. I need to use the script agaiinst a known list of VMs I have. I modified the beginning to make it part of a foreach loop. Here’s a snippet.
# Change this to the name the VM you want to enable copy paste on
$vm_Name = Get-Content C:\Temp\VM_List.txt
# info command
$VMInfos = Get-VM -Name $vm_Name
foreach($VMInfo in $VMInfos){
# function to do all of the copy paste enablements
function vmware_copypaste_enable {
# the settings
$copy_check = get-AdvancedSetting -Entity $vm_Name -Name isolation.tools.copy.disable
$paste_check = get-AdvancedSetting -Entity $vm_Name -Name isolation.tools.paste.disable
$GUI_check = get-AdvancedSetting -Entity $vm_Name -Name isolation.tools.setGUIOptions.enable
……………………………………………………………………………………..
I am getting several of these type errors:
Shutting Down Machine1 Machine2
Machine1 Machine2 is now off
starting the copy paste enablement for Machine1 Machine2
no existing copy setting found for Machine1 Machine2
setting the setting to allow copy for Machine1 Machine2
New-AdvancedSetting : Cannot process argument transformation on parameter ‘Entity’. This parameter no longer accepts an array. As an alternative you may pass multiple values by pipeline (if
supported by the parameter).
At line:30 char:29
+ New-AdvancedSetting -Entity $vm_Name -Name isolation.tools.copy.disab …
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-AdvancedSetting], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewAdvancedSetting
———————————————————————————————–
Also there were errors shutting down the machines saying VMTools was not running.
copy paste GUI setting has been enabled for Machine1 Machine2
Copy Paste has been enable for Machine1 Machine2
Turning on Machine1 Machine21
Shutdown-VMGuest : 5/1/2024 5:03:01 AM Stop-VMGuest Operation “Shutdown VM guest.” failed for VM “Machine1” for the following reason: Cannot complete operation because VMware Tools
is not running in this virtual machine.
At line:65 char:2
+ Shutdown-VMGuest -VM $vm_Name -Confirm:$false | out-null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Stop-VMGuest], VimException
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_ShutdownVmGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.StopVmGuest
appreciate any feedback you could provide
Hi Joe,
No problem!
It looks like the loop isn’t looping the VMs correctly and is trying to run all of them at once.
I think the problem is the $vm_Name is being defined as the list. If you change $vm_Name = Get-Content C:\Temp\VM_List.txt to be $vm_list = Get-Content C:\Temp\VM_List.txt
then change foreach($VMInfo in $VMInfos) to be foreach($vm_item in $vm_list)
and in your loop add the following before the function
$vm_item = $vm_Name
$VMInfo = Get-VM -Name $vm_Name
then add the function after that it might all just work.
If the VM doesn’t have VMware Tools installed the script will have errors however a way to get around that is to just turn the VM off before running the script. If the VM is off then the script won’t need VMware tools.. The part for checking if the VM was on was just because I wanted to be able to quickly run it against VMs that were already on and have it turn them off and make the changes then turn them back on.
If this doesn’t work let me know I do have some ideas on ways I can’t upgrade my script to better support looping.