Skip to content

Error: Parser: Parameter '<parameterName>' not found in context in copy() loop #1115

@Gijsreyn

Description

@Gijsreyn

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Summary

Whilst writing the documentation for #1112, I stumbled on the following error when declaring the following non-functional document:

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
  registryKey:
    type: string
    defaultValue: "HKCU\\TestKey"
  valuePrefix:
    type: string
    defaultValue: "TestValue"
resources:
- name: "[format('{0}-{1}', parameters('valuePrefix'), copyIndex())]"
  copy:
    name: registryLoop
    count: 3
  type: Microsoft.Windows/Registry
  properties:
    keyPath: "[parameters('registryKey')]"
    valueName: "ExampleValue"
    valueData:
      String: "Example Data"

Running this throws an error:

2025-09-18T02:07:10.921747Z ERROR Error: Parser: Parameter 'valuePrefix' not found in context

Steps to reproduce

  1. Open a PowerShell terminal session.
  2. Load in the document
$in = @'
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
  registryKey:
    type: string
    defaultValue: "HKCU\\TestKey"
  valuePrefix:
    type: string
    defaultValue: "TestValue"
resources:
- name: "[format('{0}-{1}', parameters('valuePrefix'), copyIndex())]"
  copy:
    name: registryLoop
    count: 3
  type: Microsoft.Windows/Registry
  properties:
    keyPath: "[parameters('registryKey')]"
    valueName: "ExampleValue"
    valueData:
      String: "Example Data"
'@
  1. Run dsc config get --input $in

Expected behavior

The document successfully applies.

Actual behavior

DSC returns an error.

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.3
PSEdition                      Core
GitCommitId                    7.5.3
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.2.0-preview.5

Visuals

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions