Powershell DSC当前配置的执行上下文是什么?

Powershell DSC当前配置的执行上下文是什么?,powershell,powershell-4.0,dsc,Powershell,Powershell 4.0,Dsc,我正在尝试通过DSC部署powershell配置文件。 配置应将.ps1文件从网络共享复制到本地路径 运行脚本失败,出现以下错误当前配置必须可以访问SourcePath。但是可以从控制台访问此路径,因此在dsc配置期间使用的是什么用户/上下文 这是剧本 在@ravikanth的回复后编辑 以及收到的错误(无效参数) DSC本地配置管理器作为系统运行。因此,它将无法访问该共享。您需要传递凭据才能访问共享。对于凭据,您需要使用证书加密密码或使用纯文本密码 有关纯文本密码,请查看我在PowerSh

我正在尝试通过DSC部署powershell配置文件。 配置应将.ps1文件从网络共享复制到本地路径

运行脚本失败,出现以下错误当前配置必须可以访问SourcePath。但是可以从控制台访问此路径,因此在dsc配置期间使用的是什么用户/上下文

这是剧本


在@ravikanth的回复后编辑


以及收到的错误(无效参数


DSC本地配置管理器作为系统运行。因此,它将无法访问该共享。您需要传递凭据才能访问共享。对于凭据,您需要使用证书加密密码或使用纯文本密码

有关纯文本密码,请查看我在PowerShell杂志上发表的文章。

如果要使用证书进行密码加密,请查看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

谢谢Ravikanth,凭据似乎已由dsc处理,但仍然出现错误。我正在更新我的问题仅发送凭据不起作用。配置数据在哪里?您需要使用Start DscConfiguration指定-ConfigurationData参数。查看我共享的PowerShell杂志链接,了解如何使用配置数据的示例。很抱歉,复制/粘贴错误配置数据出现在我的脚本中哦,好的。您已添加配置数据,但未使用它!:)请参考本文中的示例。您需要通过配置数据传递节点名称。此外,您正在使用启动DscConfiguration的credential参数。这是错误的。您必须将凭据传递给您的配置命令MyProfile。我更新了我的答案。再次感谢,我可以看到我愚蠢的错误^^。所以,如果我想传递多个机器名,就没有您在博客上建议的将configurationdata应用于所有主机(nodename=“*”)的选项了?
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
$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