Referencing local files in SetScript

Hello all!

What is the best approach to referencing and copying over files in a script resource? Does DSC actually store anything on the host that I can pull from? My development file structure looks like:

Git repo
  > DSCResources
    > MyResource
      > myConfiguration.psd1
      > myConfiguration.psm1
      > myFolderOfFiles
        > randomFile.txt

My script resource looks something like:

$dscWorkingFolder = $PSScriptRoot
Script FooBar {
        SetScript  = {
            $dscWorkingFolder = $using:dscWorkingFolder
            $pathToFile = "$($dscWorkingFolder)\myFolderOfFiles\randomFile.txt"
            ...use pathToFile variable...

The error I am getting is:

PowerShell DSC resource MSFT_ScriptResource  failed to execute Set-TargetResource functionality with error message: Exception calling \"ReadAllText\" with \"1\" argument(s): \"Could not find a part of the path...

I visit the file path in the error message (without revealing personal info the path starts with "C:\Modules\User") and the Modules folder on the C drive doesn’t even exist! Any ideas?

Thanks in advance!

Hey Marshal,

2 things to think about when trouble shooting these. When writing your resources pull back one step and treat it like a function so you can test it that way on its own. Also remember which context this is running under, localsystem.

Alex, while I appreciate the general advice, it doesn’t address the question I asked. To reword/reiterate: When a host checks in and finds a new configuration to run does the configuration itself (the source if you will) get copied or de-complied to the host in any sense? The C:\Modules folder does not exist on the hosts that failed with the error above. Is DSC overriding the $PSScriptRoot variable to a fake path?

The expected location for the DSC resource files would be C:\Program Files\WindowsPowerShell\Modules*ModuleName**ModuleVersion*\