azureconfigurationazure-virtual-machineazure-automationdsc

Delete directory content using Azure Automation DSC


I am using Azure Automation DSC to deploy some basic configurations on my Azure VMs. However, I am struggling to delete recursively all the content of C:/Temp directory and leave the directory as an empty folder.

I am using the following code:

$temp_dir           = "C:\temp\"  

File "Clean Temp Folder" # Delete $temp_dir Directory 
        { 
            Ensure          = "Absent" 
            Type            = "Directory" 
            Recurse         = $true 
            DestinationPath = $temp_dir
            Force           = $true 
        }

As soon as I assign node configuration to the VM, C:/Temp/ folder gets deleted completely, but if I recreate it manually afterwards it won't be deleted on the next DSC run even though the Force parameter is set to true.
Any suggestions are very welcome!


Solution

  • The issue was on the Azure side. While I was registering nodes in DSC, the configuration mode was set to ApplyAndMonitor. The bad thing is that the setting was not visible for the already registered node, but after re-registering the issue was solved.

    Screenshot