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 (Pull Mode)

This script will accomplish 3 things; configure a pull server, create a basic configuration to be pulled by a target node, and create a Local Configuration Manager configuration for the target node.

Execute the following code on the Pull Server:

# Step 1 Install xPSDesiredStateConfiguration
Install-Module -Name xPSDesiredStateConfiguration

# Step 2
# Create the Pull Server. 

Configuration CreatePullServer {
  param (
    [string[]]$ComputerName = 'localhost'
  )

  Import-DSCResource -ModuleName xPSDesiredStateConfiguration
  Import-DSCResource –ModuleName PSDesiredStateConfiguration

  Node $ComputerName {
    WindowsFeature DSCServiceFeature {
      Ensure = "Present"
      Name  = "DSC-Service"
    }

    xDscWebService PSDSCPullServer {
      Ensure         = "Present"
      UseSecurityBestPractices = 0
      EndpointName      = "PSDSCPullServer"
      Port          = 8080
      PhysicalPath      = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
      CertificateThumbPrint  = "AllowUnencryptedTraffic"
      ModulePath       = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
      ConfigurationPath    = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
      State          = "Started"
      DependsOn        = "[WindowsFeature]DSCServiceFeature"
    }

  }

}

#Creates the .mof file
CreatePullServer


# Apply the Pull Server configuration to the Pull Server
Start-DscConfiguration .\CreatePullServer -Wait
# 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
 
# Create a Checksum for the file listed above
 New-DscChecksum ".\exchangeservice\exch.mof"

Execute this code on the Target Node:

# Run on the target node
Configuration LCMPullConfig 
{ 
    LocalConfigurationManager 
    { 
        ConfigurationID = "EXCH";
        RefreshMode = "PULL";
        DownloadManagerName = "WebDownloadManager";
        RebootNodeIfNeeded = $true;
        RefreshFrequencyMins = 30;
        ConfigurationModeFrequencyMins = 30; 
        ConfigurationMode = "ApplyAndAutoCorrect";
        DownloadManagerCustomData = @{
        ServerUrl = "http://SCCM:8080/PSDSCPullServer/PSDSCPullServer.svc"; 
        AllowUnsecureConnection = “TRUE”}
    } 
} 

# Create the .mof meta file for the target node
LCMPullConfig

# We're essentially turning on Pull Mode on the Target
Set-DSCLocalConfigurationManager -Computer localhost -Path ./LCMPullConfig -Verbose

This is obviously a very generic and basic configuration but it will get you started.

Enjoy,
Dave

Website: www.signalwarrant.com
Twitter: @signalwarrant
Facebook: facebook.com/signalwarrant/
Google +: plus.google.com/113307879414407675617
YouTube Subscribe link: https://www.youtube.com/c/SignalWarrant1?sub_confirmation=1

Leave a Reply

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