powershell: restoration of SQL databases with a custom AzureRM script extension

I am trying to download and restore database backups on a SQL server with a custom AzureRM script extension, the file download is fine, but the restore fails with access denied (& # 39; database & # 39; teacher & # 39;). I guess this is because the script runs as the local System account and does not have permissions.

For many of the other activities that I am doing as part of the Azure automation, I can pass a credential object to handle these things without storing secrets (that is, the result of the obtain credential passes as an argument) but Set-AzureRmCustomScriptExtension only allows arguments to write "string"

How can I configure the restore-sqldatabasebackup command in that custom script extension to use the existing user who has permission to do this?