0
votes

DSC newbie here. The MOF file generation fails

PSDesiredStateConfiguration\Node : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:13 char:5 + Node localhost + ~~~~ + CategoryInfo : MetadataError: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException + FullyQualifiedErrorId : ArgumentIsNull,PSDesiredStateConfiguration\node Compilation errors occurred while processing configuration 'SQLConfig'.

Please review the errors reported in error stream and modify your configuration code appropriately. At C:\windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5 + throw $ErrorRecord + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (SQLConfig:String) [], InvalidOperationException + FullyQualifiedErrorId : FailToProcessConfiguration

    Configuration SQLConfig {
        param(
            # Parameter help description
            [Parameter(Mandatory =$true)][string[]]$serviceConfig,
            [Parameter(Mandatory =$true)][string]$DataDrive,
            [Parameter(Mandatory =$true)][string]$LogDrive

        )

    Import-DscResource -ModuleName SqlServerDsc
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node localhost
    {
        WindowsFeature Net35
        {
            Name = 'NET-Framework-Core'
            Ensure = 'Present'
        }
        WindowsFeature Net45
        {
            Name = 'NET-Framework-45-Core'
            Ensure = 'Present'
        }
        WindowsFeature Cluster
        {
            Name = 'RSAT-Clustering'
            Ensure = 'Present'
        }

        File datadrive
        {
           Type = 'Directory'
           DestinationPath = $DataDrive
           Ensure ='Present' 

        }
        File logdrive
        {
           Type = 'Directory'
           DestinationPath = $LogDrive
           Ensure ='Present' 
        }
        SqlDatabaseDefaultLocation dataPath
        {
            InstanceName = 'MSSQLSERVER'
            Path = $DataDrive
            ServerName = 'localhost'
            Type = 'Data'
            DependsOn = '[File]datadrive'
        }
        SqlDatabaseDefaultLocation logPath
        {
            InstanceName = 'MSSQLSERVER'
            Path = $LogDrive
            ServerName = 'localhost'
            Type = 'Log'
            DependsOn = '[File]logdrive'
        }
        foreach ($service in $serviceConfig) {
            ServiceSet $service
            {
                Name = $service.ServiceName
                State = $service.State
                StartupType = $service.StartupType
                Ensure = $service.Ensure
            }


        }

    }
}
  $serviceConfig=(
        @{ServiceName='MSSQLSERVER';State='Running';StartupType='Automatic';Ensure='Present'},
        @{ServiceName='SQLSERVERAGENT';State='Running';StartupType='Automatic';Ensure='Present'},
        @{ServiceName='SQLBrowser';State='Ignore';StartupType='Disabled';Ensure='Present'} ) SQLConfig -serviceConfig $serviceConfig -DataDrive "F:\Data"
    -LogDrive "H:\Log" -OutputPath "C:\dump"
1

1 Answers

1
votes

Several (small) issues.

First, you're configuring Services, not ServiceSets, so the resource name in the foreach loop at the bottom is incorrect.

Second, the name of the configured resource (you've got ServiceSet $service) needs to be a string (something more like Service $service.ServiceName)

Third, you've specified that the $ServiceConfig parameter is an array of strings, but you're supplying an array of hashtables (HashTable[]). You'll want to update the configuration parameter type.

Fourth, the State value of "Ignored" isn't valid. It should be "Running" or "Stopped"