I understand you are trying to use RunPowerShellScript from azure CLI but it is failing.
I believe the issue is with the quotations inside your script. You can see Quoting issues with PowerShell page for more explicit info. I was able to run the command via Portal without issue.
You don't need to worry about escaping characters if running the script from a file.
Please give this a try to see if it works for you. Let me know if you are still running into issues.
-------------------------------
Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.