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

About Ajeet Chouksey

With a robust background spanning more than 18 years, I am an adept Azure and Azure DevOps architect and engineer, dedicated to crafting Azure-centric solutions that prioritize customer requirements and agile methodologies. My expertise encompasses steering extensive cloud migration initiatives and advocating for Azure best practices, all aimed at streamlining costs and steering multinational teams towards success. Fueled by a passion for technological innovation, I am committed to perpetual learning, constantly advancing my proficiency in Azure, AI, MLOps, and Product Management to stay at the forefront of the industry..