使用DSC设置服务启动

时间:2019-02-08 15:29:49

标签: powershell

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

  

PSDesiredStateConfiguration \ Node:参数为null或为空。   提供一个不为null或为空的参数,然后尝试   再次命令。在第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 +抛出$ 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 个答案:

答案 0 :(得分:1)

几个(小)问题。

首先,您配置的是import {CyAndNY} from "./CyAndNYInterface"; export interface GetTable{ price?; year?; custID?; Salary?; currentYear: { currentYear: CyAndNY ; }; vlaueForNy: { vlaueforNy: CyAndNY; }; } this.cols= [ new Column('price','Price') new Column('year','Year') new Column('custID','customer ID') new Column('Salary','Salary') new Column('CyAndNY.currentYear','Current YEar') new Column('CyAndNY.vlaueForNy','Next Year Value') ] ,而不是Services,因此底部的foreach循环中的资源名称不正确。

第二,已配置资源的名称(您拥有ServiceSets)必须是字符串(更像ServiceSet $service

第三,您已经指定Service $service.ServiceName参数是一个字符串数组,但是您要提供一个哈希表数组($ServiceConfig)。您将要更新配置参数类型。

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