As you can tell, the error is not happening at all when running it manually.
I am running 2018.5.1. This first started happening, IIRC, with build 2018.4.12.
Everything runs fine on the product that is being installed, it is just not encouraging to see the RED status when it is executed through the UI, but manually it is fine.
Thanks for getting in touch! I have some info which may help here.
When you ran this script manually, did you do so running as the Octopus Tentacle’s service account? Any scripts run during deployment are executed by the account running this service.
Something else to note is that Octopus determines how the execution of a script went by reading the exit code. If your PowerShell script returns anything but a 0 it will fail.
If your script is executing correctly but is getting caught on an error, you will need to configure some error handling for the script.
If the above options do not help, please let me know.