VMware Cloud Community
c0t0d0s0
Contributor
Contributor
Jump to solution

Not able to rename centos 7 machine with Invoke-VMScript

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Are the VMware Tools installed on the VM?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
c0t0d0s0
Contributor
Contributor
Jump to solution

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean other commands via Invoke-VMScript?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
c0t0d0s0
Contributor
Contributor
Jump to solution

Yes. And I can touch files and the like. I just can't rename the vm.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
davidjwarner292
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
davidjwarner292
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos