Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

From an Azure ARM template DSC extension, a module fails to import because running scripts is disabled on this system

I'm trying to create a Windows 10 VM in Azure from an ARM template and configure it with a DSC extension to change the letter of the temporary drive.

I found the module cMoveAzureTempDrive that allow to do it easily. However when I deploy the template in Azure I receive an error saying that the module cannot be loaded because running scripts is disabled on the system :

{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"VMExtensionProvisioningError","message":"VM has reported a failure when processing extension 'Install'. Error message: "DSC Configuration 'Install' completed with error(s). Following are the first few: Importing module cMoveAzureTempDrive failed with error - File C:\Program Files\WindowsPowerShell\Modules\cMoveAzureTempDrive\cMoveAzureTempDrive.psm1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170."

More information on troubleshooting is available at https://aka.ms/VMExtensionDSCWindowsTroubleshoot "}]}

I understand that I could enable script execution from a custom script extension but it doesn't seem optimal to me that we can't use DSC module without doing that. I have the same problem with all external modules.

Do you have a solution to be able to use DSC modules?

Here is my DSC extension in the ARM template :

{
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "apiVersion": "2020-06-01",
    "name": "[concat(parameters('vmName'),'/', 'Install')]",
    "location": "[parameters('location')]",
    "tags": "[parameters('resourceTags')]",
    "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/',parameters('vmName'))]"
    ],
    "properties": {
        "publisher": "Microsoft.Powershell",
        "type": "DSC",
        "typeHandlerVersion": "2.9",
        "autoUpgradeMinorVersion":true,
        "settings": {
            "wmfVersion": "latest",
            "configuration": {
                "url": "[variables('DSCLocationURI')]",
                "script": "Install.ps1",
                "function": "Install"
            },
            "configurationArguments": {
            }
        },
        "protectedSettings": {
            "configurationUrlSasToken": "[parameters('storageAccountSASToken')]"
        }
    }
}

And here is my DSC code :

{
   
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'cAzureStorage'
    Import-DscResource -ModuleName 'cMoveAzureTempDrive'

    Node localhost
    {
        LocalConfigurationManager
        {
            ActionAfterReboot = 'ContinueConfiguration'
            RebootNodeIfNeeded = $true
        }

        cMoveAzureTempDrive cMoveAzureTempDrive
        {
            TempDriveLetter = 'T'
            Name = "MachineName"
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...