从网络共享复制 PowerShell DSC

Ric*_*ard 17 windows powershell network-share dsc

我正在尝试使用 PowerShell DSC 从网络共享复制文件夹内容。这是代码:

Configuration TestSetup {
    Node localhost {
        File Test {
            SourcePath = "\\Server\SomeShare\SomeFolder"
            DestinationPath = "E:\test"
            Recurse = $true
            Type = "Directory"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用 - 当我运行它时,我收到以下错误消息:

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
Run Code Online (Sandbox Code Playgroud)

尝试从网络共享安装软件包或从网络共享提取存档时,我得到了类似的结果。我在 Windows Server 2008 R2 SP1 上运行 PowerShell 4。

有没有办法将 PowerShell DSC 与网络共享一起使用?

Ric*_*ard 14

DSC 本地配置管理器作为本地 SYSTEM 帐户运行,而不是您的用户帐户。因此,除非获得明确的权限,否则它将无法访问网络资源。

有两种可能的情况。共享位于与应用 DSC 配置的同一台机器上(我们称之为机器 A),或者共享位于不同的机器上(我们称之为机器 B)。

如果共享在机器 A 上,则需要向 SYSTEM 用户授予 READ 权限。例如:

net share SomeShare=C:\SomeShare /GRANT:"NT AUTHORITY\SYSTEM",READ
Run Code Online (Sandbox Code Playgroud)

如果共享在机器 B 上,则需要给机器 A 的计算机帐户授予 READ 权限。 例如:

net share SomeShare=C:\SomeShare /GRANT:DOMAIN\MachineA$,READ
Run Code Online (Sandbox Code Playgroud)

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


Eri*_*ikE 5

继续DSC运行localhost以应用配置。这意味着DSC需要将资源文件分发到每台要通过DSC.

因此,从共享复制 DSC 文件时,权限管理至关重要。

DSC在该NT AUTHORITY\SYSTEM帐户下运行,除非Credential已设置该属性,否则Computer account从网络共享中提取文件时将使用该属性。

因此,并根据其中的文件是从拉动时,SYSTEM账户需要被授予read本地共享和权限Computer account需要被授予read远程共享权限。

这在理查兹的回答中有具体详细说明,它在此信息的原始博客来源上扩展了语法。