PowerShell Desired State Configuration - Part 2
PowerShell Desired State Configuration (DSC)
#DSC Configuration
[DSCResource()]
Configuration LCMSetUp
{
param()
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
RebootNodeIfNeeded = $True
ConfigurationMode = 'ApplyAndAutoCorrect'
ConfigurationModeFrequencyMins = 240
RefreshMode = 'PUSH'
}
}
#Generate MOF File
LCMSetUp -Outputpath "c:\DSC\LCMSetUp"
#Update LCM Properties
Set-DscLocalConfigurationManager -path "c:\DSC\LCMSetUp" -force -verbose
#GET DSC Local Configuration Manager
Get-DSCLocalConfigurationManager
#---------DSC Configuration to Install Windows Feature---------#
#DSC Configuration
[DSCResource()]
Configuration WindowFeatureInstall
{
param()
Node localhost
{
WindowsFeature IISInstall
{
Name="Web-Server"
Ensure="Present"
IncludeAllSubfeature = $true
}
WindowsFeature SMTP
{
Name = "SMTP-Server"
Ensure = "Present"
IncludeAllSubFeature = $true
DependsOn = "[WindowsFeature]IISInstall"
}
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
RebootNodeIfNeeded = $True
}
}
}
#Generate MOF File
WindowFeatureInstall -Outputpath "c:\DSC\WFInstall"
#Intall Configuration
Start-DSCConfiguration -path "c:\DSC\WFInstall" -ComputerName localhost -force -verbose -wait
Please do let me know your thoughts/ suggestions/ question in disqus section.
Related Posts
- PowerShell Desired State Configuration - Part 1
- Include Pester Test as part of VSTS Build
- IaC Unit Test using Pester Test
- People, Process, Product - DevOps - SonarQube Tool Assessment- 2
- People, Process, Product - DevOps - SonarQube Tool Assessment- 1
About Ajeet Chouksey

Ajeet Chouksey
Subscribe via Email
Recent Posts