-
Notifications
You must be signed in to change notification settings - Fork 63
docs: Add reference documentation for Microsoft.Adapter/PowerShell and Microsoft.Adapter/WindowsPowerShell
#1444
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
Merged
Merged
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
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
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
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
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
234 changes: 234 additions & 0 deletions
234
...eference/resources/Microsoft/Adapter/PowerShell/examples/configure-a-machine.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,234 @@ | ||
| --- | ||
| description: > | ||
| Example showing how to configure a machine using multiple class-based PowerShell DSC resources | ||
| with the Microsoft.Adapter/PowerShell adapter in a DSC configuration document. | ||
|
|
||
| ms.date: 03/23/2026 | ||
| ms.topic: reference | ||
| title: Configure a machine with the PowerShell adapter | ||
| --- | ||
|
|
||
| # Configure a machine with the PowerShell adapter | ||
|
|
||
| This example shows how to use the `Microsoft.Adapter/PowerShell` adapter to configure a machine | ||
| using multiple class-based PowerShell DSC resources in a single configuration document. These | ||
| examples use the `Microsoft.WinGet.DSC/WinGetPackage` resource from the **Microsoft.WinGet.DSC** | ||
| module to ensure several packages are installed. | ||
|
|
||
| ## Definition | ||
|
|
||
| The following configuration document defines multiple `Microsoft.WinGet.DSC/WinGetPackage` | ||
| instances. | ||
|
|
||
| Save the following YAML as `dev-tools.dsc.yaml`: | ||
|
|
||
| ```yaml | ||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| parameters: | ||
| ensureTools: | ||
| type: string | ||
| defaultValue: Present | ||
| allowedValues: | ||
| - Present | ||
| - Absent | ||
| resources: | ||
| - name: Windows Terminal | ||
| type: Microsoft.WinGet.DSC/WinGetPackage | ||
| properties: | ||
| Id: Microsoft.WindowsTerminal | ||
| Ensure: "[parameters('ensureTools')]" | ||
| - name: Visual Studio Code | ||
| type: Microsoft.WinGet.DSC/WinGetPackage | ||
| properties: | ||
| Id: Microsoft.VisualStudioCode | ||
| Ensure: "[parameters('ensureTools')]" | ||
| ``` | ||
|
|
||
| ## Setup | ||
|
|
||
| This example installs the WinGet software packages for the Windows Terminal and VS Code. The output | ||
| in this example shows the behavior when these packages aren't already installed on the system. | ||
|
|
||
| This example depends on the **Microsoft.WinGet.DSC** PowerShell module at version `1.12.440`. To | ||
| install the module, open a PowerShell session and invoke the following command: | ||
|
|
||
| ```powershell | ||
| Install-PSResource -Name Microsoft.WinGet.DSC -Version 1.12.440 | ||
| ``` | ||
|
|
||
| > [!WARNING] | ||
| > Uninstalling and reinstalling software may have unintentional side effects related to how that | ||
| > software behaves, especially if uninstalling the software removes all previously defined | ||
| > configuration for it. | ||
|
|
||
| To ensure that the packages aren't installed, invoke the following commands: | ||
|
|
||
| ```powershell | ||
| winget uninstall --id Microsoft.WindowsTerminal | ||
| winget uninstall --id Microsoft.VisualStudioCode | ||
| ``` | ||
|
|
||
| ## Test the configuration | ||
|
|
||
| To see whether the system is in the desired state, use the [`dsc config test`][01] command on the | ||
| configuration document. | ||
|
|
||
| ```powershell | ||
| dsc config test --file dev-tools.dsc.yaml | ||
| ``` | ||
|
|
||
| DSC reports the results for each instance, showing which packages need to be installed. For this | ||
| example, neither package shows as installed: | ||
|
|
||
| ```yaml | ||
| executionInformation: | ||
| # Elided for brevity | ||
| metadata: | ||
| # Elided for brevity | ||
| results: | ||
| - executionInformation: | ||
| duration: PT8.0298239S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT8.0298239S | ||
| name: Windows Terminal | ||
| type: Microsoft.WinGet.DSC/WinGetPackage | ||
| result: | ||
| desiredState: | ||
| Id: Microsoft.WindowsTerminal | ||
| Ensure: Present | ||
| actualState: | ||
| Version: null | ||
| MatchOption: EqualsCaseInsensitive | ||
| UseLatest: false | ||
| InstallMode: Silent | ||
| Id: Microsoft.WindowsTerminal | ||
| Ensure: Absent | ||
| Source: '' | ||
| _inDesiredState: false | ||
| inDesiredState: false | ||
| differingProperties: | ||
| - Ensure | ||
| - executionInformation: | ||
| duration: PT7.6445836S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT7.6445836S | ||
| name: Visual Studio Code | ||
| type: Microsoft.WinGet.DSC/WinGetPackage | ||
| result: | ||
| desiredState: | ||
| Id: Microsoft.VisualStudioCode | ||
| Ensure: Present | ||
| actualState: | ||
| UseLatest: false | ||
| Version: null | ||
| Source: '' | ||
| Ensure: Absent | ||
| Id: Microsoft.VisualStudioCode | ||
| MatchOption: EqualsCaseInsensitive | ||
| InstallMode: Silent | ||
| _inDesiredState: false | ||
| inDesiredState: false | ||
| differingProperties: | ||
| - Ensure | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| ## Apply the configuration | ||
|
|
||
| Use the [`dsc config set`][02] command to install any packages that aren't already present: | ||
|
|
||
| ```powershell | ||
| dsc config set --file dev-tools.dsc.yaml | ||
| ``` | ||
|
|
||
| ```yaml | ||
| executionInformation: | ||
| # Elided for brevity | ||
| metadata: | ||
| # Elided for brevity | ||
| results: | ||
| - executionInformation: | ||
| duration: PT34.4280028S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT34.4280028S | ||
| name: Windows Terminal | ||
| type: Microsoft.WinGet.DSC/WinGetPackage | ||
| result: | ||
| beforeState: | ||
| InstallMode: Silent | ||
| UseLatest: false | ||
| Source: '' | ||
| Id: Microsoft.WindowsTerminal | ||
| Ensure: Absent | ||
| Version: null | ||
| MatchOption: EqualsCaseInsensitive | ||
| afterState: | ||
| Version: 1.24.10921.0 | ||
| UseLatest: true | ||
| Source: winget | ||
| InstallMode: Silent | ||
| Ensure: Present | ||
| MatchOption: EqualsCaseInsensitive | ||
| Id: Microsoft.WindowsTerminal | ||
| changedProperties: | ||
| - Version | ||
| - UseLatest | ||
| - Source | ||
| - Ensure | ||
| - executionInformation: | ||
| duration: PT11.6464059S | ||
| metadata: | ||
| Microsoft.DSC: | ||
| duration: PT11.6464059S | ||
| name: Visual Studio Code | ||
| type: Microsoft.WinGet.DSC/WinGetPackage | ||
| result: | ||
| beforeState: | ||
| UseLatest: false | ||
| Ensure: Absent | ||
| Id: Microsoft.VisualStudioCode | ||
| MatchOption: EqualsCaseInsensitive | ||
| InstallMode: Silent | ||
| Source: '' | ||
| Version: null | ||
| afterState: | ||
| Id: Microsoft.VisualStudioCode | ||
| MatchOption: EqualsCaseInsensitive | ||
| Source: winget | ||
| Version: 1.119.0 | ||
| InstallMode: Silent | ||
| Ensure: Present | ||
| UseLatest: true | ||
| changedProperties: | ||
| - Source | ||
| - Version | ||
| - Ensure | ||
| - UseLatest | ||
| messages: [] | ||
| hadErrors: false | ||
| ``` | ||
|
|
||
| DSC installed both of the missing packages and reports that the state of each instance was changed | ||
| during the `set` operation. | ||
|
|
||
| ## Remove the packages | ||
|
|
||
| To uninstall the packages, override the `ensureTools` parameter when applying the configuration: | ||
|
|
||
| ```powershell | ||
| $params = @{ | ||
| parameters = @{ | ||
| ensureTools = 'Absent' | ||
| } | ||
| } | ConvertTo-Json -Compress | ||
|
|
||
| dsc config --parameters $params set --file dev-tools.dsc.yaml | ||
| ``` | ||
|
|
||
| <!-- Link references --> | ||
| [01]: ../../../../../../cli/config/test.md | ||
| [02]: ../../../../../../cli/config/set.md |
Oops, something went wrong.
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.