PowerShell / PSDscResources

MIT License
129 stars 54 forks source link

Service: Invoke-DscResource fail to update a service #197

Closed rifftual closed 3 years ago

rifftual commented 4 years ago

Details of the scenario you tried and the problem that is occurring

Invoke-DscResource -Name Service -Method Set -Property @{Ensure = 'Present'; Name = 'foo'; StartupType = 'Disabled'; State = 'Stopped'; Path = 'C:\foo.exe' } -ModuleName PSDesiredStateConfiguration

First invocation creates the service. The second one fails and it doesn't matter if you change some properties or keep them identical.

Verbose logs showing the problem

PowerShell DSC resource MSFT_ServiceResource  failed to execute Set-TargetResource functionality with error message:
The service 'foo' to create already exists with path 'C:\foo.exe'
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

Suggested solution to the issue

The DSC configuration that is used to reproduce the issue (as detailed as possible)

{Ensure = 'Present'; Name = 'foo'; StartupType = 'Disabled'; State = 'Stopped'; Path = 'C:\foo.exe'

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

PSVersion                      5.1.17763.1490
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1490
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

dev

gaelcolas commented 4 years ago

Hi @rifftual Looks like you're using PSDesiredStateConfiguration module for your resources and not this PSDscResources module.

Invoke-DscResource -Name Service -Method Set -Property @{Ensure = 'Present'; Name = 'foo'; StartupType = 'Disabled'; State = 'Stopped'; Path = 'C:\foo.exe' } -ModuleName PSDesiredStateConfiguration

rifftual commented 3 years ago

Thanks. Created an issue here PowerShell/PowerShell#14370

gaelcolas commented 3 years ago

You misunderstood my point, you should probably be using PSDscResources or better, xPSDesiredStateConfiguration module.

The built-in resources are not updated. The PsDscResources module can be fixed in some cases but does not accept non-critical changes.

The Community-maintained xPSDesiredStateConfiguration module is the most up to date, and probably the best for you to use. https://github.com/dsccommunity/xPSDesiredStateConfiguration/