Search code examples
azurepowershelldsc

Error while applying configuration using PowerShell DSC VM extension : "Compilation errors occurred while processing configuration"


I have a simple configuration that I am trying to apply to an Azure VM using PowerShell DSC extension

Configuration DSCTest
{
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
    Import-DscResource -ModuleName xPSDesiredStateConfiguration
    Node "localhost"
    {
        File ESETInstaller
        {
            Type = 'Directory'
            DestinationPath = 'C:\ESETInstaller'
            Ensure = "Present"
        }

    }
}

DSCTest

I've published this using Publish-AzVMDscConfiguration "D:\Test\DSCTest.ps1" -OutputArchivePath "D:\Test\DSCTest.ps1.zip" and then I uploaded this zip file in Azure BLOB storage. After that, I tried to apply this configuration to a VM using the following command:

Set-AzVMDscExtension -ResourceGroupName 'TestDSC' -VMName 'TestDSCVM' -ArchiveStorageAccountName 'test***********' -ArchiveResourceGroupName '******' -ConfigurationName $configurationName -ArchiveBlobName "DSCTest.ps1.zip" -ArchiveContainerName 'dsc' -Name "DSCTest" -Version 2.76

In the target machine, I can see that the DSC folder appears

enter image description here

But on the console I get the error: enter image description here

Although, I am able to successfully apply the configuration in the target machine by manually executing the command from inside that VM.

enter image description here

enter image description here

Please let me know if anyone has ever faced this issue before. Thanks.


Solution

  • The logs inside the target machine showed that the issue is with the execution policy.

    enter image description here

    In my script I changed "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned" to "Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope CurrentUser -Force" and it worked fine.