Azure Custom Script Extension. Execute script as another user

匆匆过客 提交于 2019-12-02 02:36:11

you can use Azure DSC extension to work around that

"properties": {
    "publisher": "Microsoft.Powershell",
    "type": "DSC",
    "typeHandlerVersion": "2.20",
    "autoUpgradeMinorVersion": true,
    "settings": {
        "configuration": {
            "url": "url",
            "script": "script.ps1",
            "function": "function"
        },
        "configurationArguments": {
            "regular": "arguments"
        }
    },
    "protectedSettings": {
        "configurationArguments": {
            "DomainCredentials": {
                "userName": "user",
                "password": "password"
            }
        }
    }

And in your DSC configuration add a parameter like this:

[Parameter(Mandatory)] # doesn't have to be mandatory, just copy pasting
[System.Management.Automation.PSCredential]$DomainCredentials,

Parameter name in the template must match parameter name in the dsc. You can probably figure out something similar using powershell. I personally never tried, but it should be possible.

Maybe the problem is cause by Azure Custom Script Extension running command2.ps1 as System account?

Yes, Azure Custom Script Extension runs as the System account . This means using the Azure VM Custom Script Extension we can run any sort of code even if it requires highest system privileges. As following picture, we can see the CustomScriptHandler.exe process runs as the System account.

More about Understanding Azure Custom Script Extension, refer to this article.

Please, help me make the script work.

Your scripts are OK. This issue is about system privilege. According to your errors log, if you want to run your scripts through Azure custom extension script, you can try to solve it by assign permissions to System account and change some configurations on your VM. More about how to resolve the errors, you can refer to this link.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!