尝试访问网络共享文件夹时,DSC 会返回“访问被拒绝”错误,尽管我已为其提供了有效凭据。
我正在使用 DSC 配置,其中 DSC“脚本”资源如下:
Script myScriptResource {
GetScript = {return $true}
SetScript = {
$setupShare = '\\SomeNetworkSharesFolder\subFolder'
# This line produces valid results when run directly on node VM.
$build = Get-ChildItem "FileSystem::$setupShare" -Name | Sort-Object -Descending | Select-Object -First 1 | Out-String
Write-Host "Final Build: $build"
}
TestScript = {return $false} #Always run Set-Script block!
Credential = $ValidNetworkShareCredential
PsDscRunAsCredential = $ValidNetworkShareCredential
}
我收到一个错误:
VERBOSE: [MyNodeVM]: [[Script]myScriptResource] Performing the operation "Set-TargetResource" on target "Executing t
he SetScript with the user supplied credential".
Access is denied
+ CategoryInfo : PermissionDenied: (\\SomeNetworkSharesFolder\subFolder:) [], CimException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : myNodeVM
这可能是因为节点 VM 上的 LCM 默认使用本地 SYSTEM 用户凭据。
我尝试通过导航到 Windows 服务管理器(提示:RUN然后services.msc)手动更改用户凭据,并在winRM 服务属性的登录选项卡中更改用户凭据。每次我尝试运行Windows 远程管理 (WS-Managment)服务时,我都会收到错误消息:
Windows 无法在本地计算机上启动 Windows 远程管理 (WS-Management) 服务。错误 1079:为该服务指定的帐户与为在同一进程中运行的其他服务指定的帐户不同。
我不知道如何更改 LCM 的凭据,以便它可以在执行 Get-ChildItem 时访问网络共享文件夹。