【发布时间】:2016-02-09 21:43:49
【问题描述】:
以下是我的配置示例,安装工作正常,但如果我将 '\\BuildMachine\Output\MyService.exe' 替换为较新版本,则 DSC 失败并出现文件正在使用错误。使用 DSC 升级 Windows 服务的正确方法是什么?谢谢。
Configuration ServiceTestConfiguration {
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xPSDesiredStateConfiguration
Node localhost
{
File EnsureLatestServiceExist {
Ensure = 'Present'
Type = 'File'
Checksum = 'ModifiedDate'
SourcePath = '\\BuildMachine\Output\MyService.exe'
DestinationPath = 'c:\MyService\MyService.exe'
}
xService EnsureServiceStarted {
Ensure = 'Present'
DependsOn = '[File]EnsureLatestServiceExist'
Name = 'MyService'
DisplayName = 'My Service'
Description = 'My Service'
Path = 'c:\MyService\MyService.exe'
StartupType = 'Automatic'
State = 'Running'
}
}
}
【问题讨论】:
-
我不确定您是否可以使用内置资源执行此操作。大约 6 个月前,我开始编写 DSC 解决方案,在对内置内容进行了一些修改后,我选择创建自定义资源来部署我们的服务。这使我能够编写完全自定义的逻辑来满足我们的需求,从而允许比较二进制文件和配置。我认为你应该考虑走这条路。 msdn.microsoft.com/en-us/powershell/dsc/authoringresource
标签: powershell service dsc