I am trying to use DSC in PowerShell to deploy a service. According to the Microsoft Documentation, the service resource has the following properties that can be set:
- Name
- Ensure
- BuiltInAccount
- Credential
- DependsOn
- Arguments
- StartupType
- State
I have defined a service in my DSC configuration, but I get errors on it.
This is my code:
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
}
}
}
Here are the errors I get:
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
I followed this example over on GitHub (https://gist.github.com/grenade/7677021), so I know I am going down the right path in regards to my code.
Is there some new version of DSC I need to download? How do I get it to work when I use the properties their documentation list, but which don't seem to exist?