en-us/Managing_DSC_Configurations_with_cFg.walkthru.help.txt

<#
 
### DSC configruations are a powerful way to express configuration details PowerShell.
 
 
Unfortunately, they can also be a little unweildy to manage.
 
 
Unlike functions, cmdlets, or DSC resources, a DSC configuration doesn't naturally "live" anywhere. While PowerShell is capable of it, few modules include configurations, and many configurations are written and stored in an ad-hoc way.
 
 
cFg provides a set of functions to help you manage DSC configurations:
 
* [Get-Config](/Get-Config)
* [Save-Config](/Save-Config)
* [Remove-Config](/Remove-Config)
* [Use-Config](/Use-Config)
 
Save-Config will save a PowerShell DSC Configuration for later use.
 
#>
 
configuration IISInstall {
  
    node localhost
    {
        WindowsFeature IIS
        {
            Ensure = “Present”
            Name = “Web-Server”
        }
         
        Package UrlRewrite
        {
            #Install URL Rewrite module for IIS
            Ensure = "Present"
            Name = "IIS URL Rewrite Module 2"
            Path = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi"
            Arguments = "/quiet"
            ProductId = "EB675D0A-2C95-405B-BEE8-B42A65D23E11"
        }
    }
 
}
 
Save-Config -Name IISInstall
 
<#
 
Get-Config will list saved configurations.
 
#>
 
Get-Config
 
<#
 
Using -Name with Get-Config will return it's defintion. You can then use the . operator to re-import the saved configuration.
 
#>
 
 
. Get-Config IISInstall
 
<#
 
Use-Config is very useful. It applies a saved configuration. If no parameters are provided, it will apply it to the local machine
 
#>
 
Use-Config -Name IISInstall
 
<#
 
You can also supply parameters to the configuration.
 
#>
 
Use-Config -Name ConfigWithParameters -Parameter @{
    Parameter1 = 'hello'
    Parameter2 = 'world'
}
 
<#
 
If secure parameters are required, you can provide the path to a DSC certificate
#>
 
 
Use-Config -Name ConfigWithSecret -Parameter @{
    Secret = Get-Credential
} -CertificatePath 'c:\DSC.cer'
 
<#
 
If you have the Azure PowerShell module installed, you can also use this to deploy a configuration to a VM:
#>
 
Use-Config -Name IISInstall -AzureVirtualMachine myAzureVM
 
<#
 
Configuration files are stored in $env:ProgramData\Start-Automating\cFg\
 
To remove a saved configuration, use Remove-Config
 
#>
 
Get-Config -Name IISInstall |
    Remove-Config