Pregunta

Estoy tratando de implementar un perfil de PowerShell a través de DSC. La configuración debe copiar un archivo .ps1 de un recurso compartido de red a una ruta local.

Ejecutar el script falla con el siguiente error SourcePath debe ser accesible para la configuración actual. Sin embargo, esta ruta es accesible desde la consola, por lo que se usa el contexto de usuario durante la configuración de DSC?

Aquí está el script


Editar después de la respuesta de @ 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 

y el error recibido ( argumento no válido )

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

¿Fue útil?

Solución

DSC Local Configuration Manager se ejecuta como sistema. Entonces, no tendrá acceso a la acción. Debe pasar las credenciales para acceder a la acción. Para las credenciales, debe utilizar certificados para cifrar la contraseña o usar la contraseña de texto sin formato.

Para la contraseña de texto simple, verifique el artículo que publiqué en la revista Powershell. http:// www. PowerShellMagazine.com/2013/09/26/USING-THE-CREDENCIAL-ATTRIBUTE-OF-DSC-FILE-RESOURCE/

Si desea utilizar los certificados para el cifrado de contraseña, marque la publicación del blog del equipo PS en http://blogs.msdn.com/b/powershell/archive/2014/01/31/want- to-Secure-Credentials-in-Windows-PowerShell-deseed-State-Configuración.aspx

Actualización basada en los comentarios a continuación:

The $ allnodes.nodename es la clave cuando usa datos de configuración. No reemplace eso con un nombre de nodo estático.

$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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top