I'm trying to write a powershell script that will build a test environment for me. One of the steps is rename the vm after it has been cloned from a template. I'm using the following powershell command:
$cmd=("hostnamectl set-hostname "+$vmName)
$result = Invoke-VMScript -vm $vm2 -HostCredential $vcenter -GuestCredential $guest -ScriptType Bash -ScriptText "$cmd"
$result then contains:
ScriptOutput
-----------------------------------------------------------------------------------------------------------------------| Could not set property: Connection timed out
|
-----------------------------------------------------------------------------------------------------------------------
Running the same command as root on the VM works correctly.
Any ideas what is going on?
This looks more like a guest OS issue than an Invoke-VMScript issue then.
Seen other commands through Invoke-VMScript work.
Did you already try with the nmcli command?
nmcli general hostname <your-host-name>
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are the VMware Tools installed on the VM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes. And I can run other commands like to re-ip the server. It is almost like the script is running in a jail or something.
You mean other commands via Invoke-VMScript?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes. And I can touch files and the like. I just can't rename the vm.
This looks more like a guest OS issue than an Invoke-VMScript issue then.
Seen other commands through Invoke-VMScript work.
Did you already try with the nmcli command?
nmcli general hostname <your-host-name>
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have the exact same problem. Trying to change hostname of Centos 7 with invoke-vmscript command, and I just get the message back "Could not set property: Connection timed out" Wondering if you ever figured out the problem.
Thanks.
Dave
Is the 'nmcli' command via Invoke-VMScript not working for you?
Do you get any error messages back?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Running nmcli comes back with 'command not found' Not sure why. Maybe it has to be installed? I'm not the Linux expert.
I just did a work around by putting a @reboot cron job that runs the hostnamectl command. (with invoke-vmscript) Not pretty, but it seems to work.
Would like to know why hostnamectl with invoke-vmscript doesn't work. I will also look into the nmcli option a bit further.
Thanks
Dave
Could be the CentOS version, I suspect nmcli was introduced in CentOS 7, but not 100% sure.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference