# Configuration

## DSC Configuration

DSC Configuration is similar to a PowerShell Module. To write Configurations you use a new PowerShell DSL specifically designed for writing DSC Configurations. The Configurations are not actually executed on nodes, but are used to generate a file that will actually run on the node.

## Configuration Data

You can create a configuration data file to simplify configuration files by moving common data to a separate file. This data is usually node and environment specific, that data that changes from node config to node config.

<https://technet.microsoft.com/en-us/library/dn249925.aspx> <http://blogs.msdn.com/b/powershell/archive/2014/01/09/continuous-deployment-using-dsc-with-minimal-change.aspx>

## Composite Configuration

Modularize configuration files by turning your reusable configuration files into resources and use them in other configurations. This allows you to build up your configuration for various configurations that concentrate on doing one thing well. This also makes maintenance easy because you get reusability and don't have to make updates to duplicate scripts spread across multiple files, just make the change in one file that is included where ever its functionality is needed.

Creating a Composite Configuration is similar to creating a standard DSC Configuration. One major difference is that the configuration is saved as a .schema.pdm1 file. This makes the configuration a PowerShell Module. To make it discoverable as a Module and a DSC Resource you need a Module Manifest, .psd1 file. Although you can roll your own manifest, it's PowerShell so just automate. Use the New-ModuleManifest commandlet to create the manifest for you.

```
$Name = "pneFileSystem"
$Path = $Name + ".psd1"
$RootModule = $Name + ".schema.psm1"  
$ModuleVersion = "1.0.0" 
$CompanyName = "My Company" 
$Copyright = "(c) 2015 MyCompany. All rights reserved." 
$Author = "Charles Bryant"
New-ModuleManifest -Path $Path -RootModule $RootModule -ModuleVersion $ModuleVersion -CompanyName $CompanyName -Copyright $Copyright -Author $Author
```

This is simply defining the "Path" to save the manifest as, the "RootModule" or the Composite Configuration, the "ModuleVersion" (you should increment this every time you publish changes), and the rest should be self evident.

<http://blogs.msdn.com/b/powershell/archive/2014/02/25/reusing-existing-configuration-scripts-in-powershell-desired-state-configuration.aspx>

New-ModuleManifest - <https://technet.microsoft.com/en-us/library/hh849709.aspx>

## Create MOF

Invoke the configuration to create a MOF file. The MOF will be placed in a child directory of the current directory. You can use the OutputPath parameter to specify the path to save the MOF file. If you use external configuration data it will be merged with the configuration to create the MOF. The MOF is the file that is executed against the nodes.

```
#Generate MOF
PS C:\Scripts> MyConfiguration -OutputPath "C:\Scripts\DSC\Configurations\" -MyTargetNodeName "Server001" -MyGroupName "TestGroup" 

#Generate MOF with configuration data file
PS C:\Scripts> MyConfiguration -ConfigurationData c:\scripts\ShareConfigData.psd1 -OutputPath "C:\Scripts\DSC\Configurations\"
```

Create encrypted MOF to protect credentials - <http://blogs.msdn.com/b/powershell/archive/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration.aspx>
