Script to configure target nodes to pull their configuration.

This topic contains 6 replies, has 2 voices, and was last updated by Profile photo of Simon Broad Simon Broad 1 year, 5 months ago.

  • Author
    Posts
  • #27783
    Profile photo of Simon Broad
    Simon Broad
    Participant

    This is my first foray into Powershell and DSC and I am setting up a DSC Pull Server. From your most excellent book I want to use the following code to configure the target systems to pull thier configuration from the server.

    Configuration SetPullMode
    {
       param([string]$guid)
    
       Node member2.lab.pri
       {
          LocalConfigurationManager
          {
             ConfigurationMode = 'ApplyOnly'
             ConfigurationID = $guid
             RefreshMode = 'Pull'
             DownloadManagerName = 'WebDownloadManager'
             DownloadManagerCustomData = @{
                ServerUrl = 'http://pull1.lab.pri:8080/PSDSCPullServer.svc';
                AllowUnsecureConnection = 'true' 
             }
          }
       }
    }
    
    SetPullMode -guid $guid
    Set-DSCLocalConfigurationManager -Computer member2.lab.pri -Path ./SetPullMode -Verbose
    

    What I was expecting to be able to do is parameterise the node name as well.
    Tried by changing the
    param([string]$guid)
    to
    param([string]$guid, [string]$node)

    and
    SetPullMode -guid $guid
    to
    SetPullMode -guid $guid -node $node

    then running the script .\SetPullMode -guid gdgdgdhajdagjsdgh -node myMachine

    It seemed logical, to me, but cannot get it to work – is it possible to do what I'm after?
    Isn't this how everyone would want to use this script?
    I get the error
    PSDesiredStateConfiguration\Node : Node processing is skipped since the node name is empty.
    and no mof file.

  • #27794
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Sure, you'd just need to put $node in place of the hardcoded member2 name, after the Node keyword.

  • #27823
    Profile photo of Simon Broad
    Simon Broad
    Participant

    Yes, that is pretty much what I had tried.
    Here is my modified code.

    Configuration SetPullMode_Config1
    {
    param([string]$guid,
          [string]$node
    )
    
        Node $node
        {
            LocalConfigurationManager
            {
                ConfigurationMode = 'ApplyAndAutoCorrect'
                ConfigurationID = $guid
                RefreshMode = 'Pull'
                DownloadManagerName = 'WebDownloadManager'
                DownloadManagerCustomData = @{
                ServerUrl = 'http://dscserver:8088/PSDSCPullServer.svc';
                         AllowUnsecureConnection = 'true' }
            }
        }
    }
    SetPullMode_Config1 -guid $guid -node $node 
    Set-DSCLocalConfigurationManager -Computer $node -Path ./SetPullMode -Verbose
    

    Then I run this script, test_dsc.ps1, from the command line, with the same parameters, like this...

    PS C:\Users\simon.broad\git\dsc\scripts> .\test_dsc.ps1 -guid 1611120c-24bf-4b29-a4f9-e83a0af82f4e -node myserver

    ...and end up with four mof files now?

    Directory: \scripts\test_dsc

    Mode LastWriteTime Length Name
    —- ————- —— —-
    -a— 24/07/2015 10:19 AM 2398 -guid.mof
    -a— 24/07/2015 10:19 AM 2460 1611120c-24bf-4b29-a4f9-e83a0af82f4e.mof
    -a— 24/07/2015 10:19 AM 2398 -node.mof
    -a— 24/07/2015 10:19 AM 2404 myserver.mof

    Am I not able to do what I am trying to do, or am I calling it incorrectly, or passing parameters wrongly?
    I thought I had tried every permutation of these options, but either I get multiple mof files, or it errors saying that Node name is empty.

  • #27824
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I see the confusion.

    The script itself doesn't accept parameters. The Configuration does; underneath the Configuration, the script runs the Configuration. Remove the $node there – that's where you're meant to specify the hardcoded computer name.

    If you're wanting the script itself to accept parameters, which it then passes to the Configuration, that's a separate parameter block at the top of the script, before the Configuration is defined.

  • #27826
    Profile photo of Simon Broad
    Simon Broad
    Participant

    Ah, thank you Don,
    I see now where my logic was faulty. I will give that a try.
    My aim is to get a script that I can just call with parms "-node nodeX -guid guidY" etc.

    The other thing that has me confused is the configuration that is going to be pulled.
    As per the book I created a normal push config, for a specific node, then renamed it to a guid.mof and created a checksum file and placed them on the pull server.

    This is then supposed to be able to be pulled by any node and applied to itself, but the Target in the mof file is still the original target it was created. Have I missed something, or does the pull mechanisum ignore the Target?

  • #27827
    Profile photo of Don Jones
    Don Jones
    Keymaster

    In v4, nodes pull whatever GUID file name they're told, after verifying the checksum. What's in the MOF shouldn't matter. That behavior is changed in v5 – significantly and for the better.

  • #28153
    Profile photo of Simon Broad
    Simon Broad
    Participant

    For anyone else who stumbles across this thread, here is the final code that I have tested and now use to reslove my initial question.

    param ([string]$node,
           [string]$guid
    )
    
    Configuration Set_PullMode
    {
    param([string]$node,
          [string]$guid
    )
        Node $node
        {
            LocalConfigurationManager
            {
                ConfigurationMode = 'ApplyAndAutoCorrect'
                ConfigurationID = $guid
                RefreshMode = 'Pull'
                ConfigurationModeFrequencyMins = 30 
                RefreshFrequencyMins = 15
                DownloadManagerName = 'WebDownloadManager'
                DownloadManagerCustomData = @{
                ServerUrl = 'http://dscserver:8080/PSDSCPullServer.svc';
                         AllowUnsecureConnection = 'true' }
            }
        }
    }
    Set_PullMode -node $node -guid $guid
    Set-DscLocalConfigurationManager -Computer $node -Path ./Set_PullMode -Verbose
    

    It is executed with just the two parameters, i.e. "Set_PullMode.ps1 TargetComputer ConfigGUID"

You must be logged in to reply to this topic.