I am trying to download and restore database backups against a SQL server with an AzureRM custom script extension, the files download fine but restores fail with access denied ('for database 'master'), I assume this is because the script runs as the local system account and has no permissions.

For lots of the other activities I'm doing as part of Azure automation, I can pass a credential object to handle this stuff without storing secrets (i.e. the result of get-credential passed as an argument) but Set-AzureRmCustomScriptExtension only allows arguments of type "string"

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


well, you can just construct credential object "on the fly":

$cred = [pscredential]::new('administrator',(ConvertTo-SecureString -String '!Q2w3e4r' -AsPlainText -Force))

you can obviously use variables in here and pass those into the custom script extension. another option - grant local system permission to restore databases ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.