DSC / Server Names / Script Resource

I have a DSC Configuration that gets applied to 70 servers. We recycle the AppPool nightly on each server but we do not want all of them recycling at once. We basically have a naming format such as

Server001 - Server070

The way we split this out is by what we call a POD ID, which is basically the numeric portion of the Server Name modulus the number of Pods we want.

Server004 = 004 % 4 which would make the POD = 0

Then based on which POD ID the server is part of we assign a time for the app pool recycle starting at POD 0 = 1:00 AM , POD 1 = 1:15 AM, etc.

The issue I am having is when using ConfigNames I have no way to identify the server name so the Pod can be calculated and the correct recycle time applied to the machine via the DSC config.

Does anyone know of a way I can accomplish this without creating separate configs? I have tried using the Script Resource but I have no idea how to pass back a information between the setscript and testscript blocks

Any help is appreciated.

if youre doing the calculations ON the node itself, then use $env:COMPUTERNAME
as your variable.

Assuming I understood your method :slight_smile:

Yeah, that is what I am using. See below

Script Set-ApplicationPoolRecycleTime
        {

            getscript =   {
            
                            Import-Module WebAdministration | out-null
                            $ComputerName = gc env:computername
                            $computerName -match '(LV)-(.+)-(A|B|C|D)(\d[0-9]{0,1})'
                            $tSeq = [int]$matches[4]
                            $tSeqPadded = $tSeq.ToString("000")

                            $PODID = $tSeqPadded % 4

                            switch ($PODID)
	                        {
		                        # Se tthe variable to the correct time based on the POD ID
		                        0 { $appPoolRecycleTime = "01:00:00" }
		                        1 { $appPoolRecycleTime = "01:15:00" }
		                        2 { $appPoolRecycleTime = "01:30:00" }
		                        3 { $appPoolRecycleTime = "01:45:00" }
	                        }

                            return @{
                                             
                                'RecycleTime' = "$AppPoolRecycleTime"
                              }

                             # Unload the IIS Module
	                        Remove-Module WebAdministration
                            
                         }
            testscript = { 
                            Import-Module WebAdministration | out-null
                         
                            # Set the App Pool Property to the correct time.
	                        $tempTime = Get-ItemProperty -Path "IIS:\AppPools\KBB" -Name Recycling.periodicRestart.schedule.collection[0].Value -ErrorAction SilentlyContinue | select Value
	                        $iisRecycleTime = [string]$tempTime.Value

                            $value = getscript
                        
	                        # Unload the IIS Module
	                        Remove-Module WebAdministration
	
	                        If ($($iisRecycleTime) -eq $($value['RecycleTime']))
	                        {
		                        return $true
	                        }
	                        else
	                        {
		                        return $false
	                        }
                              
                        }

            setscript = {

   	                        # Load the IIS Module
	                        Import-Module WebAdministration | out-null

  	
	                        # Set the App Pool Property to the correct time.
	                        Set-ItemProperty -Path "IIS:\AppPools\KBB" -Name Recycling.periodicRestart.schedule -Value @{ value = "$($AppPoolRecycleTime['RecycleTime']))" }
	
	                        # Unload the IIS Module
	                        Remove-Module WebAdministration

                        }             
          }
`

You want to deploy same configuration to all 70 nodes, correct? Your configuration would look something like this.

Configuration ApplicationPoolRecycleTime
{
    node ApplicationPoolRecycleTime
    {
        Script Set-ApplicationPoolRecycleTime
        {

            getscript =   {
            
                            Import-Module WebAdministration | out-null
                            $ComputerName = gc env:computername
                            $computerName -match '(LV)-(.+)-(A|B|C|D)(\d[0-9]{0,1})'
                            $tSeq = [int]$matches[4]
                            $tSeqPadded = $tSeq.ToString("000")

                            $PODID = $tSeqPadded % 4

                            switch ($PODID)
	                        {
		                        # Se tthe variable to the correct time based on the POD ID
		                        0 { $appPoolRecycleTime = "01:00:00" }
		                        1 { $appPoolRecycleTime = "01:15:00" }
		                        2 { $appPoolRecycleTime = "01:30:00" }
		                        3 { $appPoolRecycleTime = "01:45:00" }
	                        }

                            return @{
                                             
                                'RecycleTime' = "$AppPoolRecycleTime"
                              }

                             # Unload the IIS Module
	                        Remove-Module WebAdministration
                            
                         }
            testscript = { 
                            Import-Module WebAdministration | out-null
                         
                            # Set the App Pool Property to the correct time.
	                        $tempTime = Get-ItemProperty -Path "IIS:\AppPools\KBB" -Name Recycling.periodicRestart.schedule.collection[0].Value -ErrorAction SilentlyContinue | select Value
	                        $iisRecycleTime = [string]$tempTime.Value

                            $value = getscript
                        
	                        # Unload the IIS Module
	                        Remove-Module WebAdministration
	
	                        If ($($iisRecycleTime) -eq $($value['RecycleTime']))
	                        {
		                        return $true
	                        }
	                        else
	                        {
		                        return $false
	                        }
                              
                        }

            setscript = {

   	                        # Load the IIS Module
	                        Import-Module WebAdministration | out-null

  	
	                        # Set the App Pool Property to the correct time.
	                        Set-ItemProperty -Path "IIS:\AppPools\KBB" -Name Recycling.periodicRestart.schedule -Value @{ value = "$($AppPoolRecycleTime['RecycleTime']))" }
	
	                        # Unload the IIS Module
	                        Remove-Module WebAdministration

                        }             
          }
     }
 }
ApplicationPoolRecycleTime

Now you can put generated ApplicationPoolRecycleTime.mof (and associated checksum) on the pull server and configure all 70 nodes to get the configuration with name ‘ApplicationPoolRecycleTime’.
I hope I haven’t misunderstood your question.

That was my NEXT way of doing it if I could not come up with this… see below this actually works. Just needed to step away and come back to it.


Script Set-ApplicationPoolRecycleTime
        {

            getscript =  {

                            
                            
                         }
            testscript = { 
                            Import-Module WebAdministration | out-null

                            $ComputerName = gc env:computername
                            $computerName -match '(LV)-(.+)-(A|B|C|D)(\d[0-9]{0,1})'
                            $tSeq = [int]$matches[4]
                            $tSeqPadded = $tSeq.ToString("000")

                            $PODID = $tSeqPadded % 4

                            switch ($PODID)
	                        {
		                        # Se tthe variable to the correct time based on the POD ID
		                        0 { $appPoolRecycleTime = "01:00:00" }
		                        1 { $appPoolRecycleTime = "01:15:00" }
		                        2 { $appPoolRecycleTime = "01:30:00" }
		                        3 { $appPoolRecycleTime = "01:45:00" }
	                        }
                         
                            # Set the App Pool Property to the correct time.
	                        $tempTime = Get-ItemProperty -Path "IIS:\AppPools\KBB" -Name Recycling.periodicRestart.schedule.collection[0].Value -ErrorAction SilentlyContinue | select Value
	                        $iisRecycleTime = [string]$tempTime.Value
                      
	                        # Unload the IIS Module
	                        Remove-Module WebAdministration
	
	                        If ($($iisRecycleTime) -eq $($appPoolRecycleTime))
	                        {
		                        return $true
	                        }
	                        else
	                        {
		                        return $false
	                        }
                              
                        }

            setscript = {

   	                        # Load the IIS Module
	                        Import-Module WebAdministration | out-null

                            $ComputerName = gc env:computername
                            $computerName -match '(LV)-(.+)-(A|B|C|D)(\d[0-9]{0,1})'
                            $tSeq = [int]$matches[4]
                            $tSeqPadded = $tSeq.ToString("000")

                            $PODID = $tSeqPadded % 4

                            switch ($PODID)
	                        {
		                        # Se tthe variable to the correct time based on the POD ID
		                        0 { $appPoolRecycleTime = "01:00:00" }
		                        1 { $appPoolRecycleTime = "01:15:00" }
		                        2 { $appPoolRecycleTime = "01:30:00" }
		                        3 { $appPoolRecycleTime = "01:45:00" }
	                        }

   	
	                        # Set the App Pool Property to the correct time.
	                        Set-ItemProperty -Path "IIS:\AppPools\KBB" -Name Recycling.periodicRestart.schedule -Value @{ value = "$($appPoolRecycleTime)" }
	
	                        # Unload the IIS Module
	                        Remove-Module WebAdministration

                        }
        }