我正尝试使用PowerShell DSC从networking共享复制文件夹内容。 这里是代码:
Configuration TestSetup { Node localhost { File Test { SourcePath = "\\Server\SomeShare\SomeFolder" DestinationPath = "E:\test" Recurse = $true Type = "Directory" } } }
这不工作,但是 – 当我运行它时,我得到以下错误信息:
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
尝试从networking共享中安装软件包或从networking共享中提取存档时,我会得到类似的结果。 我在Windows Server 2008 R2 SP1上运行PowerShell 4。
有没有办法使用PowerShell DSC与networking共享?
DSC本地configurationpipe理器以本地SYSTEM帐户运行,而不是您的用户帐户。 因此,它将无法访问networking资源,除非它被授予明确的权限。
有两种可能的情况。 要么共享与DSCconfiguration应用于同一台机器上(我们称之为机器A),或者共享位于另一台机器上(让我们称之为机器B)。
如果共享位于计算机A上,则需要将READ权限授予SYSTEM用户。 例如:
net share SomeShare=C:\SomeShare /GRANT:"NT AUTHORITY\SYSTEM",READ
如果共享位于计算机B上,则需要将READ权限授予计算机A的计算机帐户。例如:
net share SomeShare=C:\SomeShare /GRANT:DOMAIN\MachineA$,READ
资料来源: http : //www.powershellmagazine.com/2013/09/02/copying-powershell-modules-and-custom-dsc-resources-using-dsc/
DSC在localhost上运行,以便应用configuration。 这意味着DSC资源文件需要分发给每台要通过DSCconfiguration的机器。
因此,从共享复制DSC文件时,权限pipe理至关重要。
DSC在NT AUTHORITY\SYSTEM帐户下运行,除非已设置Credential属性,否则在从networking共享中提取文件时使用Computer account 。
因此,根据文件从哪里被提取, SYSTEM帐户需要被授予对本地共享的read权限,并且Computer account需要被授予对远程共享的read权限。
这在Richards答案中有具体的详细说明,它在原始博客源代码中扩展了此信息的语法。
目前我没有时间进一步研究,但看起来可以安全地传递本地configurationpipe理器使用的凭据。 事实上,在他的博客中,他的示例使用文件资源从networking共享中提取文件。 我希望尽快尝试一下,然后再回来更好的实现这个答案。
TechNet博客: 希望在Windows PowerShell期望的状态configuration中保护凭据? – 由Travis Plunk
PowerShell几乎和旧的cmd shell一样愚蠢。 对UNCpath的支持仍然非常有限。 考虑到这一点…你有尝试别名UNCpath吗? 即
New-PSDrive -Name UNCPath -PSProvider FileSystem -Root \\Server\SomeShare\
然后参考UNCPath:\SomeFolder的pathUNCPath:\SomeFolder 。 完成后用Remove-PSDrive清理。
此外,有时您可以指定FileSystem::\\Server\SomeShare\SomeFolder作为path。 我见过这种情况不起作用的情况,但值得一试。