Unable to install new version of agent (fleet managed)

Hello.
I try to install agent with fleet integration but i don't understand why it doesn't work.

in fleet i have this script:

$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri http://srv-ansible:8088/endpoints/asset-directory/content/elastic/beats/elastic-agent/elastic-agent-8.17.0-windows-x86_64.zip -OutFile elastic-agent-8.17.0-windows-x86_64.zip 
Expand-Archive .\elastic-agent-8.17.0-windows-x86_64.zip -DestinationPath .
cd elastic-agent-8.17.0-windows-x86_64
.\elastic-agent.exe install --url=https://evo-vs-ef01.eveno.fermetures.fr:8220 --enrollment-token=NFRQckpKQUJZNjFmUDNzOUUzSFY6TFlrUEhRdFdRdDZQY1Fyb0JJT0lRUQ== --force --insecure

but when i run in PS as admin:
[ ] Uninstall failed [0s] Error: unable to find elastic-agent.exe on path: exec: "elastic-agent.exe": cannot run executable found relative to current directory

I have already elastic-agent 8.14.1 on this server... i try to stop service before but same result!

And if i try to uninstall manually :

PS C:\temp\elastic-agent-8.17.0-windows-x86_64> cd 'C:\Program Files\Elastic\Agent\'
PS C:\Program Files\Elastic\Agent> .\elastic-agent.exe uninstall
Elastic Agent will be uninstalled from your system at C:\Program Files\Elastic\Agent. Do you want to continue? [Y/n]:Y
[    ] Failed to uninstall agent  [0s] Error uninstalling. Printing logs
Error: error uninstalling agent: uninstall must be run from outside the installed path 'C:\Program Files\Elastic\Agent'

Someone can help me ?

Hi @jay29300 Welcome to the community!

A couple things

1st) You can upgrade a fleet managed agents from the Fleet UI, that is the correct way not uninstalling and re-installing... That is the correct way

2nd) IF you want to uninstall the Elastic Agent you need to carefully follow the commands

The proper command as shown in the docs is here

C:\"Program Files"\Elastic\Agent\elastic-agent.exe uninstall

if you CD to the directory it will not properly uninstall ...

The way I found to fix this in the past is to re-install the original version of the agent back over... get it running correctly then Upgrade from the UI...