Hi Antonio,
Although it's possible to install AMA directly I've been installing Arc and then I use collections rules out of Azure to push out the features I need - eg. AMA, FIM, etc.
Have you considered installing Arc instead?
Or if you're just referring to VMs inside azure then you should just need to set up a data collection rule and there should be no need for running scripts.
Or if you can provide the steps to replicate your problem I'd be happy to try it.
Reference
https://learn.microsoft.com/en-us/azure/azure-arc/servers/plan-at-scale-deployment