I have been working on a project for some time and ran into an issue where I was trying to run a shell script remotely on a Centos 7 VM and it just hangs. Turns out there is an issue with executing firewalld commands from PowerCLI using the invoke-VMscript commandlet. Here is example of the code I was trying to run.
Invoke-VMScript -ScriptText "sh /root/apache.sh” -vm "$VMName" -GuestUser 'root' -GuestPassword 'VMware1!' -ScriptType bash
Here is the apache.sh file
#!/bin/sh sudo yum -y install httpd sudo systemctl enable httpd sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload sudo systemctl start httpd.service
When I login and run the apache.sh file locally it works fine. So i found a workaround by scheduling a one time task using the at command. more info on that here. So the new command is
Invoke-VMScript -ScriptText "echo sh /root/apache.sh | at now + 1 minutes” -vm "$VMName" -GuestUser 'root' -GuestPassword 'VMware1!' -ScriptType bash
This way it runs from the Linux OS after PowerCLI has exited.