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
