Hello
I'm trying to automate the population of /etc/hosts via the following command. The command ran on the host will populate with the IP address hostname, FQDN
echo "`hostname -i` $HOSTNAME `echo $HOSTNAME| cut -d"." -f1`" >> /etc/hosts
but running the same command via script will not fulfill the purpose. It will append the command at the end of /etc/hosts
I tried skipping double quotes using backslash but I get the following error
$GuestCred=$Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for VM", "root", "")
$script = @"
echo \"`hostname -i` $HOSTNAME `echo $HOSTNAME| cut -d'.' -f1`\" >> /etc/hosts
"@
Invoke-VMScript -VM $VM -GuestCredential $GuestCred -ScriptType bash -ScriptText $script
ScriptOutput
-----------------------------------------------------------------------------------------------------------------------| cut: invalid byte, character or field list
| Try 'cut --help' for more information.
|
-----------------------------------------------------------------------------------------------------------------------
Has to be a syntax issue.