cloud-riders.ES Powershell,WINDOWS DSC: Aplicar, obtener y probar configuraciones en un nodo (1)

DSC: Aplicar, obtener y probar configuraciones en un nodo (1)DSC: Aplicar, obtener y probar configuraciones en un nodo (1)

Esta guía le mostrará cómo trabajar con configuraciones en un nodo de destino. Esta guía se divide en los siguientes pasos:

Aplicar una configuración:

Para aplicar y administrar una Configuración, necesitamos generar un archivo «.mof». El siguiente código representará una configuración simple que se utilizará a lo largo de esta guía.

Configuration Sample
{
# This will generate two .mof files, a localhost.mof, and a server02.mof
Node localhost, server02
{
File SampleFile
{
DestinationPath = ‘C:\Temp\temp.txt’
Contents = ‘This is a simple resource to show Configuration functionality on a Node.’
}
}
}

The -OutputPath parameter is built into every Configuration automatically.
The value of -OutputPath determines where the .mof file should be stored, once compiled.

Sample -OutputPath «C:\Temp\»

Compiling this configuration will yield two «.mof» files.

Mode LastWriteTime Length Name
—- ————- —— —-
-a—- 11/27/2018 7:29 AM 2.13KB localhost.mof
-a—- 11/27/2018 7:29 AM 2.13KB server02.mof

Para aplicar una configuración, use el cmdlet Start-DSCConfiguration. El parámetro -Path especifica un directorio donde residen los archivos «.mof». Si no se especifica -Computername, Start-DSCConfiguration intentará aplicar cada configuración al nombre de la computadora especificado por el nombre del archivo ‘.mof’ (.mof). Especifique -Verbose to Start-DSCConfiguration para ver una salida más detallada.

Start-DSCConfiguration -Path C:\Temp\ -Verbose

Si no se especifica -Wait, verá un trabajo creado. El trabajo creado tendrá un ChildJob por cada archivo «.mof» procesado por Start-DSCConfiguration.

Id Name PSJobTypeName State HasMoreData Location Command
— —- ————- —– ———– ——– ——-
45 Job45 Configuratio… Running True localhost,server02 Start-DSCConfiguration…

Si una configuración tarda mucho tiempo y desea detenerla, puede usar Stop-DSCConfiguration para detener la aplicación en el nodo local.

Stop-DSCConfiguration -Force

Once complete, you can view the status of the jobs through the job object returned by Get-Job.

$job = Get-Job
$job.ChildJobs

Id Name PSJobTypeName State HasMoreData Location Command
— —- ————- —– ———– ——– ——-
49 Job49 Configuratio… Completed True localhost Start-DSCConfiguration…
50 Job50 Configuratio… Completed True server02 Start-DSCConfiguration…

Para ver el resultado Verbose, use los siguientes comandos para ver el flujo Verbose para cada ChildJob. Para obtener más información sobre los trabajos de PowerShell, consulte about_Jobs.

View the verbose output of the localhost job using array indexing.

$job.ChildJobs[0].Verbose

Perform operation ‘Invoke CimMethod’ with following parameters, »methodName’ = SendConfigurationApply,
‘className’ = MSFT_DSCLocalConfigurationManager,’namespaceName’ = root/Microsoft/Windows/DesiredStateConfiguration’.
An LCM method call arrived from computer SERVER01 with user sid S-1-5-21-124525095-708259637-1543119021-1282804.
[SERVER01]: LCM: [ Start Set ]
[SERVER01]: LCM: [ Start Resource ] [[File]SampleFile]
[SERVER01]: LCM: [ Start Test ] [[File]SampleFile]
[SERVER01]: [[File]SampleFile] The destination object was found and no action is required.
[SERVER01]: LCM: [ End Test ] [[File]SampleFile] in 0.0370 seconds.
[SERVER01]: LCM: [ Skip Set ] [[File]SampleFile]
[SERVER01]: LCM: [ End Resource ] [[File]SampleFile]
[SERVER01]: LCM: [ End Set ]
[SERVER01]: LCM: [ End Set ] in 0.2400 seconds.
Operation ‘Invoke CimMethod’ complete.

A partir de PowerShell 5.0, se agregó el parámetro -UseExisting a Start-DSCConfiguration. Al especificar -UseExisting, indica al cmdlet que use la configuración aplicada existente en lugar de una especificada por el parámetro -Path.

Start-DSCConfiguration -UseExisting -Verbose -Wait

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Related Post