我正在尝试通过DSC部署PowerShell配置文件。 配置应将.ps1文件从网络共享复制到本地路径。
运行脚本失败,并显示以下错误当前配置必须可以访问SourcePath。但是可以从控制台访问此路径,因此在dsc配置期间使用了哪些用户/上下文?
这是脚本
@ ravikanth的回复后编辑
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword=$true
}
)
}
Configuration MyProfile
{
param ([string[]]$MachineName,
[PSCredential]$Credential)
Node $MachineName
{
Log startconfig
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "starting the file resource with ID MyProfile with $($myinvocation.mycommand) user : $env:username"
}
File profile
{
Credential=$credential
Ensure = 'Present'
SourcePath = "\\web-mridf\powershell\profil_1.ps1"
DestinationPath = "c:\temp\test.txt"
Type = "File" # Default is "File".
DependsOn = "[Log]startconfig"
}
Log AfterDirectoryCopy
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "Finished running the file resource with ID MyProfile"
DependsOn = "[File]profile" # This means run "MyProfile" first.
}
}
}
MyProfile -MachineName web-mridf -OutputPath c:\temp\dsc
Start-DscConfiguration -Path c:\temp\dsc -credential (get-credential("DOMAIN\user")) -force -verbose -Wait
收到错误(无效参数)
PS C:\temp> .\dsc.ps1
Répertoire : C:\temp\dsc
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 04/06/2014 10:54 2834 web-mridf.mof
COMMENTAIRES : Effectuez l'opération « Invoquer une méthode CIM » avec les
paramètres suivants : « 'methodName' = SendConfigurationApply,'className' =
MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration ».
COMMENTAIRES : [WEB-MRIDF] : [[File]profile]
SourcePath must be accessible for current configuration.
COMMENTAIRES : [WEB-MRIDF] : [[File]profile] The
related file/directory is: \\web-mridf\powershell\profil_1.ps1.
SourcePath must be accessible for current configuration. The related
file/directory is: \\web-mridf\powershell\profil_smac.ps1. . L'ID de ressource
associé est [File]profile.
+ CategoryInfo : InvalidArgument : (:) [], CimException
+ FullyQualifiedErrorId : MI RESULT 4
+ PSComputerName : web-mridf
COMMENTAIRES : [WEB-MRIDF] : Gestionnaire de configuration local : [ Fin
Définir ]
La fonction SendConfigurationApply n'a pas réussi.
+ CategoryInfo : InvalidArgument : (root/Microsoft/...gurationMan
ager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 4
+ PSComputerName : web-mridf
COMMENTAIRES : L'opération « Invoquer une méthode CIM » est terminée.
COMMENTAIRES : Le temps nécessaire à l'exécution du travail de configuration
est de 0.881 secondes
答案 0 :(得分:1)
DSC本地配置管理器作为SYSTEM运行。因此,它无法访问共享。您需要传递凭据才能访问共享。对于凭据,您需要使用证书来加密密码或使用纯文本密码。
对于纯文本密码,请查看我在PowerShell Magazine上发布的文章。 http://www.powershellmagazine.com/2013/09/26/using-the-credential-attribute-of-dsc-file-resource/
如果您想使用证书进行密码加密,请查看http://blogs.msdn.com/b/powershell/archive/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration.aspx上的PS团队博客文章
根据以下评论进行更新:
$ AllNodes.Nodename是使用配置数据时的关键。不要用静态节点名替换它。
$ConfigurationData = @{
AllNodes = @(
@{
NodeName="*"
PSDscAllowPlainTextPassword=$true
}
@{
NodeName="ServerName"
}
)
}
Configuration MyProfile
{
param (
[PSCredential]$Credential
)
Node $AllNodes.NodeName
{
Log startconfig
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "starting the file resource with ID MyProfile with $($myinvocation.mycommand) user : $env:username"
}
File profile
{
Credential=$credential
Ensure = 'Present'
SourcePath = "e:\powershell\profil_smac.ps1"
DestinationPath = "c:\temp\test2.txt2"
Type = "File" # Default is "File".
DependsOn = "[Log]startconfig"
}
Log AfterDirectoryCopy
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "Finished running the file resource with ID MyProfile"
DependsOn = "[File]profile" # This means run "MyProfile" first.
}
}
}
MyProfile -configurationdata $configurationdata -machinename "web-mridf.groupe.sa.colas.com" -credential (get-credential("groupe\sys-mac-smacsr")) -OutputPath c:\temp\dsc
Start-DscConfiguration -Path c:\temp\dsc -force -verbose -Wait