PowerShell / PowerShell/DSC

Implement PowerShell import extension

Open
#1,021 0 comments 0 reactions 1 assignee View on GitHub

@michaeltlombardi is already working on this.

Since Aug 4, 2025.

Issue-Bug
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

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

I'm experiencing a weird issue while attempting to implement a PowerShell import extension. Firstly, I defined the extension manifest as such:

{
    "$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
    "type": "Microsoft.DSC.Extension/PowerShell",
    "version": "0.1.0",
    "description": "Enable passing PowerShell v2 configuration document file directly to DSC, but requires pwsh executable to be available.",
    "import": {
        "fileExtensions": ["ps1"],
        "executable": "pwsh",
        "args": [
            "-NoLogo",
            "-NonInteractive",
            "-NoProfile",
            "-ExecutionPolicy",
            "Bypass",
            "-Command",
            {
                "fileArg": "Get-Content"
            },
            "$args | ./convert-resource.ps1 $args"
        ]
    }
}

Then, I created the convert-resource.ps1 as such:

[CmdletBinding()]
param (
    [Parameter(ValueFromPipeline = $true)]
    [string[]]$stringInput
)

begin {
    $lines = [System.Collections.Generic.List[string]]::new()

    $scriptModule = Import-Module "$PSScriptRoot/convertDscResource.psd1" -Force -PassThru
}

process {
    foreach ($line in $stringInput) {
        $lines.Add($line)  
    }
}

end {
    if ($lines.Count -ne 0) {
        $result = $scriptModule.invoke( { param($lines) Build-DscConfigDocument -Content $lines }, ($lines | Out-String) )

        return ($result | ConvertTo-Json -Depth 10 -Compress)
    }
}

The Build-DscConfigDocument generates a valid JSON string that can be ran by the engine. However, when I try to run it, somehow the process fails early on with the following error message:

Image

Strangely enough, grabbing the exact same line that dsc.exe tries to execute from procmon, returns the JSON string:

Image
Steps to reproduce
  1. Clone the following repository: https://github.com/Gijsreyn/operation-methods.git
  2. Check out the implement-powershell-import-extension
  3. Build the project
  4. Run the following example `dsc config get --file test.ps1
# test.ps1
configuration MyConfiguration {
        Import-DscResource -ModuleName PSDesiredStateConfiguration
        Node localhost
        {
            Environment CreatePathEnvironmentVariable
            {
                Name = 'TestPathEnvironmentVariable'
                Value = 'TestValue'
                Ensure = 'Present'
                Path = $true
                Target = @('Process')
            }
        }
    }

[!NOTE]
If you're wondering why I'm using the Get-Content; I have tried many combinations but couldn't figure one out properly. Open for suggestions!

Expected behavior
The configuration runs successfully
Actual behavior
See error in description
Error details

Environment data
Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
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.3

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.