【问题标题】:Delete directory content using Azure Automation DSC使用 Azure 自动化 DSC 删除目录内容
【发布时间】:2022-01-14 10:05:04
【问题描述】:

我正在使用 Azure 自动化 DSC 在我的 Azure VM 上部署一些基本配置。但是,我正在努力递归删除 C:/Temp 目录的所有内容并将目录保留为空文件夹。

我正在使用以下代码:

$temp_dir           = "C:\temp\"  

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

一旦我将节点配置分配给 VM,C:/Temp/ 文件夹就会被完全删除,但如果我之后手动重新创建它,即使 Force 参数设置为,它也不会在下一次 DSC 运行时被删除真的。
非常欢迎任何建议!

【问题讨论】:

标签: azure configuration azure-virtual-machine azure-automation dsc


【解决方案1】:

我建议您使用Script resource,否则如果您只想使用File resource,请尝试如下所示。

$temp_dir           = "C:\temp\"  

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

$temp_dir           = "C:\temp\"  

File "Create empty Temp Folder" # Create empty $temp_dir Directory 
        { 
            Ensure          = "Present" 
            Type            = "Directory" 
            DestinationPath = $temp_dir
            Force           = $true 
        }

【讨论】:

  • 有趣的方法。感谢您的想法!
【解决方案2】:

问题出在 Azure 方面。当我在 DSC 中注册节点时,配置模式设置为 ApplyAndMonitor。 不好的是已经注册的节点看不到设置,但是重新注册后问题就解决了。

Screenshot

【讨论】:

    猜你喜欢
    • 2017-09-16
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 2017-12-29
    • 2017-07-05
    • 2015-02-09
    • 2011-01-13
    • 1970-01-01
    相关资源
    最近更新 更多