【问题标题】:DSC File Resource - overwrite/replace file contentsDSC 文件资源 - 覆盖/替换文件内容
【发布时间】:2021-04-11 11:06:52
【问题描述】:

我正在尝试使用 DSC 文件资源更新一个目录中的一些特定文件。在我的示例中,我要更新(即覆盖)的文件存在于目标中,但为空 (0KB)。源中的文件具有完全相同的名称,但有一些内容。使用下面的代码,源文件的内容不会复制到目标文件。知道为什么吗?提前致谢。

Ensure = "Present"
Type = "File"
Force = $true
SourcePath = "somepath\myfile.txt"
DestinationPath = "anotherpath\myfile.txt"

【问题讨论】:

    标签: file resources dsc


    【解决方案1】:

    根据答案of a similar question here:您可能想尝试将checksum = 'modifiedDate'matchsource = $true 添加到您的属性中。

    official doc 在回答其他问题后已移动。

    File TheFile {
        Ensure = "Present"
        Type = "File"
        Force = $true
        SourcePath = "somepath\myfile.txt"
        DestinationPath = "anotherpath\myfile.txt"
        checksum = 'modifiedDate'
        matchsource = $true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多