PowerShell DSC: deleting a Windows Service

This is simple and it works – thanks DSC. Code is here.

I want to declaratively delete a Windows Service… I tell it what I want, it figures out how. Part of that is not involving me in interactive decisions about what to do if it is already Absent, to use the Service provider keyword. I have said the required state is Absent, just make it so.

I decided that the Fax service was one I would never need, so that is my test case. As ever with actions against Windows Services, make sure the Services dialog is closed when you perform the action, else it will just hang.

The code to achieve that is immediately below the service dialog.

That is then compiled into MOF format (the . .\ServiceManager.ps1 screenshot), and then we execute (Start-DscConfiguration…). Net result is no Fax Service in Services after this.

Chef does not currently have the ability to delete a Windows Service, as far as I can see here.