【问题标题】:Set service startup using DSC设置服务启动使用DSC
【发布时间】:2019-07-02 21:14:30
【问题描述】:

DSC 新手在这里。 MOF 文件生成失败

PSDesiredStateConfiguration\Node :参数为空或空。 提供一个不为 null 或空的参数,然后尝试 再次命令。在 line:13 char:5 + Node localhost + ~~~~ + CategoryInfo : MetadataError: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException + FullyQualifiedErrorId : ArgumentIsNull,PSDesiredStateConfiguration\node 编译错误 处理配置“SQLConfig”时发生。

请查看错误流中报告的错误并修改您的 适当的配置代码。在 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"

【问题讨论】:

    标签: powershell


    【解决方案1】:

    几个(小)问题。

    首先,您配置的是Services,而不是ServiceSets,所以底部foreach循环中的资源名称不正确。

    其次,配置资源的名称(你有ServiceSet $service)需要是一个字符串(更像Service $service.ServiceName

    第三,您已指定 $ServiceConfig 参数是一个字符串数组,但您提供的是一个哈希表数组 (HashTable[])。您需要更新配置参数类型。

    第四,“忽略”的状态值无效。它应该是“正在运行”或“已停止”

    【讨论】:

    • 顺便说一句,在最终的 SQLConfig 调用中添加 -Debug 可以让您逐步完成大量配置,以查看它在哪里崩溃。不是灵丹妙药,但会有所帮助。
    猜你喜欢
    • 2021-09-27
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2019-05-27
    • 1970-01-01
    相关资源
    最近更新 更多