Replies: 2 comments
-
@dummys I tried to follow what you're attempting to achieve. Even thought I like variables and parameters, might the following example by Mikey in the repository solve your case: https://github.com/PowerShell/DSC/blob/9fc9a807c72b4e49901d9ec8188ab4dcafebf55d/dsc/examples/winps_script.dsc.yaml |
Beta Was this translation helpful? Give feedback.
0 replies
-
hi, # 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
metadata:
Microsoft.DSC:
securityContext: elevated
variables:
svcnumber: "temp"
resources:
- type: Microsoft.Windows/WindowsPowerShell
name: Get the number for user services using old powershell
properties:
resources:
- name: Get the number of user for user services
type: PSDesiredStateConfiguration/Script
properties:
GetScript: |
$svcname = $(Get-Service | Where-Object {$_.Name -like 'WpnUs*'}).Name
$text = $svcname -split "_"
$using:svcnumber = $text[1]
# Returning result must be this type of hashtable
@{Result=$text[1]}
TestScript: |
# TestScript must return a boolean
$true
SetScript: |
$svcname = $(Get-Service | Where-Object {$_.Name -like 'WpnUs*'}).Name
$text = $svcname -split "_"
# Returning result must be this type of hashtable
@{Result=$text[1]} But I get the following error:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To modify some registry key value, I need to retrieve the SID of the user. in DSC 2.0 I do like this:
And then I use
${mysid}
I tried to do the same on DSC 3.0 but I was not able to execute powershell code within my yaml configuration document.
Unfortunately the documentation on using variables in not good because it didnt' exist any examples, even copilot is not giving good result.I was able find documentation on parameters, thus I tried to do the same with variables: https://learn.microsoft.com/en-gb/powershell/dsc/reference/schemas/config/functions/parameters?view=dsc-3.0
I tried a lot of things without make it work like:
Beta Was this translation helpful? Give feedback.
All reactions