Powershell 使用DSC设置服务启动
我是新手。MOF文件生成失败 PSDesiredStateConfiguration\Node:参数为null或空。 请提供一个不为null或空的参数,然后重试 再次指挥。第13行字符:5+节点本地主机+~~~+ CategoryInfo:MetadataError::[PSDesiredStateConfiguration\node], ParentContainesErrorRecordException+FullyQualifiedErrorId: ArgumentIsNull,PSDesiredStateConfiguration\node编译错误 处理配置“SQLConfig”时发生 请查看错误流中报告的错误,并修改您的 适当的配置代码。在 C:\windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5+抛出$ErrorRecord+~~~~~~~~~~~~~~~~~~~~~~~~~+类别信息: InvalidOperation:SQLConfig:String[],InvalidOperationException+ FullyQualifiedErrorId:FailToProcessConfiguration 几个小问题 首先,您正在配置服务,而不是服务集,因此底部foreach循环中的资源名称不正确 其次,您已配置的资源的名称ServiceSet$service需要是一个字符串,更像service$service.ServiceName 第三,您已经指定$ServiceConfig参数是一个字符串数组,但您提供的是一个hashtables数组HashTable[]。您需要更新配置参数类型Powershell 使用DSC设置服务启动,powershell,Powershell,我是新手。MOF文件生成失败 PSDesiredStateConfiguration\Node:参数为null或空。 请提供一个不为null或空的参数,然后重试 再次指挥。第13行字符:5+节点本地主机+~~~+ CategoryInfo:MetadataError::[PSDesiredStateConfiguration\node], ParentContainesErrorRecordException+FullyQualifiedErrorId: ArgumentIsNull,PSDes
第四,忽略的状态值无效。它应该正在运行或停止顺便说一句,在最后的SQLConfig调用中添加-Debug可以让您逐步完成许多配置,以查看它的运行位置。不是银弹,但会有帮助。
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"