liveBook · Manning

DependsOn property

As explained in 100 SQL Server Mistakes and How to Avoid Them

The DependsOn property declares that one DSC resource must be processed after another resource or configuration condition.

Mistake: configuring dependent DSC resources as if execution order were automatic. Remote-access settings and login creation require a SQL Server instance; running them first causes connection errors. section 8.9

SQL Server installation scenario

Define SqlSetup first, then assign DependsOn to SqlConfiguration and login resources so DSC processes them only after the instance exists. Apply the compiled configuration with Start-DscConfiguration -Path 'C:\dsc\InstallSql' -Verbose. section 8.9

Listing 8.9 Creating a DSC configuration
Configuration InstallSql {
   param (
       $SqlInstanceName = 'MSSQLSERVER',
       $Edition
   )

   Import-DscResource -ModuleName SqlServerDsc

   if ($Edition -eq 'Developer') {
       $ProductKey = '22222-00000-00000-00000-00000'
   } elseif ($edition -eq 'Standard') {
       $ProductKey = '00000-00000-00000-00000-00000'
   } elseif ($edition -eq 'Enterprise') {
       $ProductKey = '00000-00000-00000-00000-00000'
   }
   
   node localhost {
         SqlSetup 'InstallInstance' {
              InstanceName        = $SqlInstanceName
              Features            = 'SQLENGINE'
              SourcePath          = 'C:\SQL Media'
              SQLSysAdminAccounts = @('Administrator')
              ProductKey          = $ProductKey
         }

         SqlConfiguration 'RemoteAccess' {
             InstanceName = $SqlInstanceName
             OptionName   = 'remote access'
             OptionValue  = 1

             DependsOn    = '[SqlSetup]InstallInstance'
         }

         SqlLogin 'AddSqlAdmin' {
             Ensure       = 'Present'
             Name         = 'Pete'
             InstanceName = $SqlInstanceName
             LoginType    = 'WindowsUser'

             DependsOn    = '[SqlSetup]InstallInstance'
         }   
    }
}

Inspect the DSC configuration structure that creates the instance and declares subsequent configuration resources. section 8.9

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains the dependency failure, demonstrates the ordering pattern, and shows compiled and applied configuration, without detailing property syntax.
Examples
Uses SQL Server setup, remote-access disabling, login creation, a compiled MOF file, and Start-DscConfiguration.
What it assumes
Assumes basic PowerShell DSC configuration knowledge and teaches ordering through a SQL Server installation example.
What you can do after
Configure DSC dependencies that prevent SQL Server resources from running before the instance is available.
How it connects
Connects DSC resources with SQL Server instances, configuration compilation, MOF files, and scheduled configuration enforcement.

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.