Script configuration through VMware PowerCLI

Hi all. I’m working with 1.4 rolling release 20220228.

I am trying to find a way to change the hostname of a router vm using invoke-script. I’ve tried a couple of different things, including suggestions from a few years ago on these forums, but nothing seems to be working.

I would like to include this in a larger script that deploys several routers from a master image.

First option – I create a simple script in my users home directory, with the intent of providing the actual hostname on the command line

source /opt/vyatta/etc/functions/script-template
set system host-name $1

presumably, ./ testing-hostname would set the hostname to testing-hostname

but – the recommendation in the documents is to run with sg vyattacfg -c ./
result is permission denied. My user is not in the vyattacfg group, so I am not sure how to circumvent that.

Second Option - I create a little script in PowerCLI (took the idea from a post on this topic from a couple of years ago – except the OP was doing a show command, not a set command)

/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set system host-name $hn
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end
invoke-vmscript -vm test-vyos-router -guestuser vyos -guespassword vyos -scripttype bash -scripttext $script

This doesn’t seem to want to expand $hm, as I get the result:
“configuration path: [system host-name] requires a value” “set failed”

If I surround $hn with " " or ’ ', or I just provide a value (with or without " " / ’ ') I get a slightly different result:
sh: line 1 /validate-value: No such file or directory
Invalid value
Value validation failed
Set failed

Any assistance would be greatly appreciated!