Windows – PowerShell DSC copy from network share

dscnetwork-sharepowershellwindows

I am trying to use PowerShell DSC to copy folder contents from a network share. Here is the code:

Configuration TestSetup {
    Node localhost {
        File Test {
            SourcePath = "\\Server\SomeShare\SomeFolder"
            DestinationPath = "E:\test"
            Recurse = $true
            Type = "Directory"
        }
    }
}

This doesn't work however – when I run it I get the following error message:

The related file/directory is: \\Server\SomeShare\SomeFolder.
The path cannot point to the root directory or to the root of a net share.
SourcePath must be specified if you want to configure the destination directory recursively. Make sure that SourcePath is a directory and that it is accessible.
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : MI RESULT 4
    + PSComputerName        : localhost

The SendConfigurationApply function did not succeed.
    + CategoryInfo          : InvalidArgument: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 4
    + PSComputerName        : localhost

I get similar results when trying to install a package from a network share or extract an archive from a network share. I'm running PowerShell 4 on Windows Server 2008 R2 SP1.

Is there a way to use PowerShell DSC with network shares?

Best Answer

The DSC Local Configuration Manager runs as the local SYSTEM account, not your user account. It therefore won't be able to access network resources unless it is given explicit permissions.

There are two possible situations. Either the share is on the same machine as the DSC configuration is being applied to (let's call this machine A) or the share is on a different machine (let's call this machine B).

If the share is on machine A, READ permissions need to be granted to the SYSTEM user. For example:

net share SomeShare=C:\SomeShare /GRANT:"NT AUTHORITY\SYSTEM",READ

If the share is on machine B, READ permissions need to be granted to the computer account of machine A. For example:

net share SomeShare=C:\SomeShare /GRANT:DOMAIN\MachineA$,READ

Source: http://www.powershellmagazine.com/2013/09/02/copying-powershell-modules-and-custom-dsc-resources-using-dsc/