我正在尝试在 PowerShell 中使用 DSC 来部署服务。根据Microsoft 文档,服务资源具有可以设置的以下属性:
- 姓名
- 确保
- 内置帐户
- 凭据
- 取决于
- 论据
- 启动类型
- 状态
我在我的 DSC 配置中定义了一个服务,但我得到了错误。
这是我的代码:
Configuration ServiceDeployConfig
{
param(
[string[]]$ComputerName="localhost",
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceDeployPath,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceDisplayName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceExecutable,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceUserame,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $servicePassword
)
Node $ComputerName
{
File serviceFiles
{
Ensure = "Present"
SourcePath = "\\Path\to\exe\$serviceExecutable"
DestinationPath = $serviceDeployPath
}
Service serviceInstall
{
Ensure = "Present"
Name = $serviceName
Credential = New-Object System.Management.Automation.PSCredential ($serviceUserame, (ConvertTo-SecureString $servicePassword -AsPlainText -Force))
DependsOn = "[File]serviceFiles"
Arguments = "-binaryPathName $serviceDeployPath\$serviceExecutable", "-displayName $serviceDisplayName"
StartupType = Automatic
Status = Start
}
}
}
这是我得到的错误:
At line:43 char:13
+ Ensure = "Present"
+ ~~~~~~
The member 'Ensure' is not valid. Valid members are 'DependsOn', 'Name', 'State', 'StartupType', 'BuiltInAccount', 'Credential'. Please update your script and try again.
At line:47 char:13
+ Arguments = "-binaryPathName $serviceDeployPath\$serviceExecutable", ...
+ ~~~~~~~~~
The member 'Arguments' is not valid. Valid members are 'DependsOn', 'Name', 'State', 'StartupType', 'BuiltInAccount', 'Credential'. Please update your script and try again.
At line:49 char:13
+ Status = Start
+ ~~~~~~
The member 'Status' is not valid. Valid members are 'DependsOn', 'Name', 'State', 'StartupType', 'BuiltInAccount', 'Credential'. Please update your script and try again.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidInstanceProperty
我在 GitHub ( https://gist.github.com/grenade/7677021 ) 上遵循了这个示例,所以我知道我的代码走的是正确的道路。
我需要下载一些新版本的 DSC 吗?当我使用其文档列表的属性但似乎不存在时,如何使其工作?