Install Elastic agent with PowerShell script

We have created a PowerShell script to install the elastic agent. The script is pushed by GPO. When the installation is done by the GPO, then the elastic agent file structure is created under C:\Program Files, but the directory C:\Program Files\Elastic\Agent is missing the Elastic-agent.exe. the Folder C:\Program Files\Elastic\Agent\data contains a folder called elastic-agent-de80b0, which does contain the Elastic-Agent.exe. When we run the script interactively, then the elastic agent is installed as intended. Something seems to go wrong during the installation by GPO, but what is a mystery. We have added the --path.log=$Path switch to get some installation logs, but no installation log is created. Any idea what is going wrong here?

It isn't a GPO issue as the script is runs. The script has a logfile, in which each step of the script is written to a logfile. It does not seem to be a code issue, as the scripts runs as intended when running interactively. I do not think that the script has a permissions issue, as the scripts runs under the system account which is administrator. Antivirus logs do not show that the installation is blocked, and the eventvwt isn't showing anything helpful. Have tested on 4 different machines, and all have the similar issue.