Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

PowerShell Desired State Configuration (DSC) How-To for Beginners (Push Model)

In this video, I cover only a few very basic PowerShell Desired State Configuration Manager (DSC) concepts.
1. The terminology
2. How to create a Local Configuration Manager (LCM) configuration
3. How to push the LCM configuration to the target node
4. How to create a basic DSC configuration to maintain the MSExchangeTransport service in a running state.
5. How to push the DSC configuration to the target.
And
6. How to detect and correct drift from the desired configuration state.
Using the Push model of DSC is good for organizations that don’t have access to server resources to install the DSC feature on a server. It’s also good for administrators that don’t have access to enterprise management tools such as the use of Group Policy or SCCM among many others.
The next video will cover standing up a DSC Pull Server and making the process a little more dynamic.

Enjoy!

 

 

# Get all the DSC CMDLets
Get-Command -Noun dsc*

# Get Available Resources
# Refer to powershellgallery.com for additional resources
Get-DscResource

# What can we configure for each resource
Get-DscResource File | Select -ExpandProperty Properties

# Step 1
# Generate a LCM Config for target node
# Target Node LCM Configuration
Configuration LCMConfig {
    # Parameters
  Param([string[]]$ComputerName = "localhost")
    # Target Node
    Node $ComputerName {
      # LCM Resource
      LocalConfigurationManager {
        ConfigurationMode = "ApplyAndAutoCorrect"
        ConfigurationModeFrequencyMins = 30
        }
      }
   }

   # Generate MOF File
   LCMConfig -ComputerName EXCH

   # Check LCM Settings on target node
   Get-DscLocalConfigurationManager -CimSession EXCH 

   # Apply the LCMConfig for each Target Node
   Set-DscLocalConfigurationManager -Path LCMConfig

   # Check the LCM Config again
   # Notice the CoConfigurationModeFrequencyMins value changed to 30
   Get-DscLocalConfigurationManager -CimSession EXCH

 

# Your Configuration
Configuration ExchangeService {

    # Parameters
    # Accepts a string value computername or defaults to localhost
    Param([string[]]$ComputerName = "localhost")

    # Target Node
    Node $ComputerName {

        # Service Resource
        # Ensure a service is started
        Service MSExchangeTransport {
            Name = 'MSExchangeTransport'
            State = 'Running'
        }
    }
}

# Generate the .MOF files
ExchangeService -ComputerName EXCH

  # MOF files are created in whatever directory you're in in the PS Console
  # 1 MOF file per target node

# Apply the configuration
Start-DscConfiguration -path ExchangeService -Wait -Verbose -Force

# View Deployed Configurations
Get-DscConfiguration -CimSession EXCH

#Testing Config (detect drift)
Test-DscConfiguration -CimSession EXCH

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.