|
| 1 | +--- |
| 2 | +description: > |
| 3 | + Example showing how to configure a machine using multiple class-based PowerShell DSC resources |
| 4 | + with the Microsoft.Adapter/PowerShell adapter in a DSC configuration document. |
| 5 | +
|
| 6 | +ms.date: 03/23/2026 |
| 7 | +ms.topic: reference |
| 8 | +title: Configure a machine with the PowerShell adapter |
| 9 | +--- |
| 10 | + |
| 11 | +This example shows how to use the `Microsoft.Adapter/PowerShell` adapter to configure a machine |
| 12 | +using multiple class-based PowerShell DSC resources in a single configuration document. These |
| 13 | +examples use the `Microsoft.WinGet.DSC/WinGetPackage` resource from the **Microsoft.WinGet.DSC** |
| 14 | +module to ensure several packages are installed. |
| 15 | + |
| 16 | +> [!NOTE] |
| 17 | +> Run this example with `dsc.exe` version 3.2.0 or later and the **Microsoft.WinGet.DSC** |
| 18 | +> PowerShell module installed. Install the module with: |
| 19 | +> `Install-PSResource Microsoft.WinGet.DSC` |
| 20 | +
|
| 21 | +## Configuration document |
| 22 | + |
| 23 | +The following configuration document defines multiple `Microsoft.WinGet.DSC/WinGetPackage` |
| 24 | +instances. Each instance sets `directives.requireAdapter` to `Microsoft.Adapter/PowerShell`. |
| 25 | + |
| 26 | +Save the following YAML as `dev-tools.dsc.yaml`: |
| 27 | + |
| 28 | +```yaml |
| 29 | +$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json |
| 30 | +parameters: |
| 31 | + ensureTools: |
| 32 | + type: string |
| 33 | + defaultValue: Present |
| 34 | + allowedValues: |
| 35 | + - Present |
| 36 | + - Absent |
| 37 | +resources: |
| 38 | +- name: PowerShell 7 |
| 39 | + type: Microsoft.WinGet.DSC/WinGetPackage |
| 40 | + directives: |
| 41 | + requireAdapter: Microsoft.Adapter/PowerShell |
| 42 | + properties: |
| 43 | + Id: Microsoft.PowerShell |
| 44 | + Ensure: "[parameters('ensureTools')]" |
| 45 | +- name: Windows Terminal |
| 46 | + type: Microsoft.WinGet.DSC/WinGetPackage |
| 47 | + directives: |
| 48 | + requireAdapter: Microsoft.Adapter/PowerShell |
| 49 | + properties: |
| 50 | + Id: Microsoft.WindowsTerminal |
| 51 | + Ensure: "[parameters('ensureTools')]" |
| 52 | +- name: Visual Studio Code |
| 53 | + type: Microsoft.WinGet.DSC/WinGetPackage |
| 54 | + directives: |
| 55 | + requireAdapter: Microsoft.Adapter/PowerShell |
| 56 | + properties: |
| 57 | + Id: Microsoft.VisualStudioCode |
| 58 | + Ensure: "[parameters('ensureTools')]" |
| 59 | +``` |
| 60 | +
|
| 61 | +## Test the configuration |
| 62 | +
|
| 63 | +Run the configuration test to check whether the packages are installed: |
| 64 | +
|
| 65 | +```powershell |
| 66 | +dsc config test --file dev-tools.dsc.yaml |
| 67 | +``` |
| 68 | + |
| 69 | +DSC reports the results for each instance, showing which packages need to be installed. |
| 70 | + |
| 71 | +## Apply the configuration |
| 72 | + |
| 73 | +Run the configuration set to install any packages that aren't already present: |
| 74 | + |
| 75 | +```powershell |
| 76 | +dsc config set --file dev-tools.dsc.yaml |
| 77 | +``` |
| 78 | + |
| 79 | +## Remove the packages |
| 80 | + |
| 81 | +To uninstall the packages, override the `ensureTools` parameter when applying the configuration: |
| 82 | + |
| 83 | +```powershell |
| 84 | +dsc config set --file dev-tools.dsc.yaml --parameters '{"ensureTools": "Absent"}' |
| 85 | +``` |
| 86 | + |
| 87 | +<!-- Link references --> |
| 88 | +[01]: ../../../../../../cli/config/test.md |
| 89 | +[02]: ../../../../../../cli/config/set.md |
0 commit comments