Copying a remote file on change

This topic contains 3 replies, has 3 voices, and was last updated by  Patrick van Staveren 2 years, 1 month ago.

  • Author
  • #40543


    I'm new to DSC, but have used other CM tools before. I'm trying to figure out how to best manage a few text files which I want to distribute to all of my DSC hosts. The text files will change periodically, so I need DSC to check them at every run. I'm using pull mode.

    A good example is C:\Windows\system32\WindowsPowerShell\v1.0\profile.ps1
    It's a text file which I can host anywhere – on my DSC pull server and serve via HTTP or SMB share (or anywhere else that makes sense.)

    I wrote examples using the DSC File Resource [1] and using xRemoteFile [2] fetching over HTTP. The first resource simply checks that the destination exists, and if it does, stops short – it doesn't compare the two files. The second, xRemoteFile, uses caching to try and optimize and minimize use of HTTP requests – which means that it only detects if the file has been locally modified. It never re-checks the server for new content.

    Is there a pre-existing module / method out there that I should be using for something like this? If not, I'm going to write one 🙂



  • #40565

    Arie H

    as far as I remember you need to use the MatchSource property.

    This will tell the resource to get the newer version of the files from the original source if they are newer then the ones it finds on the node

  • #40726

    Nitin Gupta

    You probably want to use the combination of MatchSource and Checksum.
    MatchSource –> Always compare the DestinationPath with the SourcePath. The default is false, meaning we will use cached information.
    Checksum –> The checksum type to use when determining whether two files are the same. Valid values are "SHA-1", "SHA-256", "SHA-512", "CreatedDate", "ModifiedDate"},Values{"SHA-1", "SHA-256", "SHA-512", "CreatedDate" and "ModifiedDate".

  • #44250

    Answering my own question as I've learned a few things about xRemoteFile...
    1) MatchSource defaults to true – so it's not necessary to set this parameter.
    2) The caching done by xRemoteFile is cleared when the LCM receives new configuration from the pull server. If I re-generate my MOFs (even no-op changes) then xRemoteFile voids it's cache and re-copies the file as needed.

You must be logged in to reply to this topic.