-
Notifications
You must be signed in to change notification settings - Fork 63
docs: Add reference documentation for Microsoft.Windows/Service
#1522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gijsreyn
wants to merge
1
commit into
PowerShell:main
Choose a base branch
from
Gijsreyn:update-winservice-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+723
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
197 changes: 197 additions & 0 deletions
197
...rence/resources/Microsoft/Windows/Service/examples/configure-windows-service.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| --- | ||
| description: > | ||
| Example showing how to use the Microsoft.Windows/Service resource in a DSC configuration | ||
| document to enforce the desired state of Windows services. | ||
| ms.date: 05/08/2026 | ||
| ms.topic: reference | ||
| title: Configure a Windows service | ||
| --- | ||
|
|
||
| # Configure a Windows service | ||
|
|
||
| This example shows how you can use the `Microsoft.Windows/Service` resource in a DSC configuration | ||
| document to enforce the desired configuration and runtime status of multiple Windows services. | ||
|
|
||
| > [!IMPORTANT] | ||
| > **Set** operations for this resource require an elevated (administrator) process context. Run | ||
| > your terminal or PowerShell session as Administrator before using `dsc config set`. | ||
|
|
||
| ## Definition | ||
|
|
||
| The configuration document for this example defines two instances of the `Service` resource. | ||
|
|
||
| The first instance ensures that the Windows Update service (`wuauserv`) is stopped and configured | ||
| for manual start. The second instance ensures that the Windows Time service (`W32Time`) is running | ||
| and configured to start automatically. | ||
|
|
||
| :::code language="yaml" source="service.config.dsc.yaml"::: | ||
|
|
||
| Copy the configuration document and save it as `service.config.dsc.yaml`. | ||
|
|
||
| ## Setup | ||
|
|
||
| The output in this example assumes that the system has the `wuauserv` service stopped with a manual | ||
| startup and the `W32Time` service stopped with an automatic startup. You can set the system to | ||
| this starting state with the following commands: | ||
|
|
||
| ```powershell | ||
| Set-Service -Name wuauserv -StartupType Manual -Status Stopped | ||
| Set-Service -Name W32Time -StartupType Automatic -Status Stopped | ||
| ``` | ||
|
|
||
| ## Test the configuration | ||
|
|
||
| To see whether the system is already in the desired state, use the [dsc config test][01] command. | ||
|
|
||
| ```powershell | ||
| dsc config test --file ./service.config.dsc.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| executionInformation: | ||
| # Elided for brevity | ||
| metadata: | ||
| # Elided for brevity | ||
| results: | ||
| - executionInformation: | ||
| duration: PT0.1113118S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.1113118S | ||
| name: Ensure Windows Update is stopped and set to manual start | ||
| type: Microsoft.Windows/Service | ||
| result: | ||
| desiredState: | ||
| name: wuauserv | ||
| status: Stopped | ||
| startType: Manual | ||
| actualState: | ||
| name: wuauserv | ||
| displayName: Windows Update | ||
| description: Enables the detection, download, and installation of updates for Windows and other programs. If this service is disabled, users of this computer will not be able to use Windows Update or its automatic updating feature, and programs will not be able to use the Windows Update Agent (WUA) API. | ||
| _exist: true | ||
| status: Stopped | ||
| startType: Manual | ||
| executablePath: C:\Windows\system32\svchost.exe -k netsvcs -p | ||
| logonAccount: LocalSystem | ||
| errorControl: Normal | ||
| dependencies: | ||
| - rpcss | ||
| inDesiredState: true | ||
| differingProperties: [] | ||
| - executionInformation: | ||
| duration: PT0.0353328S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0353328S | ||
| name: Ensure Windows Time service is running | ||
| type: Microsoft.Windows/Service | ||
| result: | ||
| desiredState: | ||
| name: W32Time | ||
| status: Running | ||
| startType: Automatic | ||
| actualState: | ||
| name: W32Time | ||
| displayName: Windows Time | ||
| description: Maintains date and time synchronization on all clients and servers in the network. If this service is stopped, date and time synchronization will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start. | ||
| _exist: true | ||
| status: Stopped | ||
| startType: Automatic | ||
| executablePath: C:\Windows\system32\svchost.exe -k LocalService | ||
| logonAccount: NT AUTHORITY\LocalService | ||
| errorControl: Normal | ||
| inDesiredState: false | ||
| differingProperties: | ||
| - status | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| The `inDesiredState` field for the first instance is `true` because the Windows Update service is | ||
| already `Stopped` with `Manual` start, so no change is required. The second instance is `false`: | ||
| the Windows Time service exists and already has `startType: Automatic`, but its `status` is | ||
| `Stopped` while the desired state requires `Running`. Only `status` is listed in | ||
| `differingProperties`. | ||
|
|
||
| ## Set the configuration | ||
|
|
||
| To enforce the desired state, use the [dsc config set][02] command. | ||
|
|
||
| ```powershell | ||
| dsc config set --file ./service.config.dsc.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| executionInformation: | ||
| # Elided for brevity | ||
| metadata: | ||
| # Elided for brevity | ||
| results: | ||
| - executionInformation: | ||
| duration: PT0.0924309S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.0924309S | ||
| name: Ensure Windows Update is stopped and set to manual start | ||
| type: Microsoft.Windows/Service | ||
| result: | ||
| beforeState: | ||
| name: wuauserv | ||
| status: Stopped | ||
| startType: Manual | ||
| afterState: | ||
| name: wuauserv | ||
| displayName: Windows Update | ||
| description: Enables the detection, download, and installation of updates for Windows and other programs. If this service is disabled, users of this computer will not be able to use Windows Update or its automatic updating feature, and programs will not be able to use the Windows Update Agent (WUA) API. | ||
| _exist: true | ||
| status: Stopped | ||
| startType: Manual | ||
| executablePath: C:\Windows\system32\svchost.exe -k netsvcs -p | ||
| logonAccount: LocalSystem | ||
| errorControl: Normal | ||
| dependencies: | ||
| - rpcss | ||
| changedProperties: null | ||
| - executionInformation: | ||
| duration: PT0.3682548S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT0.3682548S | ||
| name: Ensure Windows Time service is running | ||
| type: Microsoft.Windows/Service | ||
| result: | ||
| beforeState: | ||
| name: W32Time | ||
| displayName: Windows Time | ||
| description: Maintains date and time synchronization on all clients and servers in the network. If this service is stopped, date and time synchronization will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start. | ||
| _exist: true | ||
| status: Stopped | ||
| startType: Automatic | ||
| executablePath: C:\Windows\system32\svchost.exe -k LocalService | ||
| logonAccount: NT AUTHORITY\LocalService | ||
| errorControl: Normal | ||
| afterState: | ||
| name: W32Time | ||
| displayName: Windows Time | ||
| description: Maintains date and time synchronization on all clients and servers in the network. If this service is stopped, date and time synchronization will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start. | ||
| _exist: true | ||
| status: Running | ||
| startType: Automatic | ||
| executablePath: C:\Windows\system32\svchost.exe -k LocalService | ||
| logonAccount: NT AUTHORITY\LocalService | ||
| errorControl: Normal | ||
| changedProperties: | ||
| - status | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| The Windows Update instance shows `changedProperties: null` because it was already in the desired | ||
| state and DSC made no changes to it. The Windows Time instance lists only `status` in | ||
| `changedProperties` because DSC only needed to start the service. The `startType` was already | ||
| `Automatic` and required no update. | ||
|
|
||
| <!-- Link definitions --> | ||
| [01]: ../../../../../cli/config/test.md | ||
| [02]: ../../../../../cli/config/set.md | ||
87 changes: 87 additions & 0 deletions
87
docs/reference/resources/Microsoft/Windows/Service/examples/get-service-status.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| --- | ||
| description: > | ||
| Example showing how to use the Microsoft.Windows/Service resource with DSC to retrieve the | ||
| current state of a Windows service. | ||
| ms.date: 05/08/2026 | ||
| ms.topic: reference | ||
| title: Get service status | ||
| --- | ||
|
|
||
| # Get service status | ||
|
|
||
| This example shows how you can use the `Microsoft.Windows/Service` resource to retrieve the | ||
| current configuration and runtime status of a Windows service. | ||
|
|
||
| ## Get the state of a service by name | ||
|
|
||
| The following snippet shows how to use the resource with the [dsc resource get][01] command to | ||
| retrieve the current state of the `wuauserv` (Windows Update) service by its key name. | ||
|
|
||
| ```powershell | ||
| $instance = @{ name = 'wuauserv' } | ConvertTo-Json -Compress | ||
|
|
||
| dsc resource get --resource Microsoft.Windows/Service --input $instance | ||
| ``` | ||
|
|
||
| When the service exists, DSC returns its full configuration and status: | ||
|
|
||
| ```yaml | ||
| actualState: | ||
| name: wuauserv | ||
| displayName: Windows Update | ||
| description: Enables the detection, download, and installation of updates for Windows and other programs. If this service is disabled, users of this computer will not be able to use Windows Update or its automatic updating feature, and programs will not be able to use the Windows Update Agent (WUA) API. | ||
| _exist: true | ||
| status: Stopped | ||
| startType: Manual | ||
| executablePath: C:\WINDOWS\System32\svchost.exe -k netsvcs -p | ||
| logonAccount: LocalSystem | ||
| errorControl: Normal | ||
| dependencies: | ||
| - rpcss | ||
| ``` | ||
|
|
||
| ## Get the state of a service by display name | ||
|
|
||
| You can also identify the service by its display name when you don't know the key name. | ||
|
|
||
| ```powershell | ||
| $instance = @{ displayName = 'Windows Update' } | ConvertTo-Json -Compress | ||
|
|
||
| dsc resource get --resource Microsoft.Windows/Service --input $instance | ||
| ``` | ||
|
|
||
| DSC resolves the display name to the corresponding key name and returns the same result. | ||
|
|
||
| ## Get the state of a non-existent service | ||
|
|
||
| When you request a service that isn't registered with the SCM, the resource returns `_exist: false` | ||
| and leaves all other properties unset. | ||
|
|
||
| ```powershell | ||
| $instance = @{ name = 'MyMissingService' } | ConvertTo-Json | ||
|
|
||
| dsc resource get --resource Microsoft.Windows/Service --input $instance | ||
| ``` | ||
|
|
||
| ```yaml | ||
| actualState: | ||
| name: MyMissingService | ||
| _exist: false | ||
| ``` | ||
|
|
||
| ## Export all services | ||
|
|
||
| To retrieve the state of every service registered on the system, use the [dsc resource export][02] | ||
| command without an input instance. | ||
|
|
||
| ```powershell | ||
| dsc resource export --resource Microsoft.Windows/Service | ||
| ``` | ||
|
|
||
| DSC writes a single JSON configuration document to stdout. That document contains a `resources` | ||
| array with one entry per service, which you can pipe to a file or process further with other | ||
| tools. | ||
|
|
||
| <!-- Link definitions --> | ||
| [01]: ../../../../../cli/resource/get.md | ||
| [02]: ../../../../../cli/resource/export.md |
15 changes: 15 additions & 0 deletions
15
docs/reference/resources/Microsoft/Windows/Service/examples/service.config.dsc.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=https://aka.ms/dsc/schemas/v3/bundled/config/document.vscode.json | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| resources: | ||
| - name: Ensure Windows Update is stopped and set to manual start | ||
| type: Microsoft.Windows/Service | ||
| properties: | ||
| name: wuauserv | ||
| status: Stopped | ||
| startType: Manual | ||
| - name: Ensure Windows Time service is running | ||
| type: Microsoft.Windows/Service | ||
| properties: | ||
| name: W32Time | ||
| status: Running | ||
| startType: Automatic |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.