Skip to content

WindowsPowerShell adapter should not discover resources unavailable in Windows PowerShell #707

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

Closed
3 tasks done
michaeltlombardi opened this issue Mar 17, 2025 · 3 comments · Fixed by #777
Closed
3 tasks done
Labels
Issue-Bug Something isn't working Need-Review

Comments

@michaeltlombardi
Copy link
Collaborator

Prerequisites

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

Summary

In #698, a user reported an error trying to use a PSDSC resource with the Microsoft.Windows/WindowsPowerShell adapter. In that case, the root issue was that even though the adapter discovered a resource, it couldn't be used in the adapter because the PSDSC resource module was installed to a PowerShell module path, not in the Windows PowerShell module path.

The Windows PowerShell adapter should only discover and advertise resources usable in Windows PowerShell.

Checking my WindowsPSAdapterCache.json file showed PowerShell module folders alongside Windows PowerShell module folders, indicating the discovery process is somehow including modules that may have PSDSC resources but can't be discovered by the Windows PowerShell adapter and lead to confusing errors.

Steps to reproduce

  1. Invoke dsc resource list --adapter Microsoft.Windows/WindowsPowerShell
  2. Check the WindowsPSAdapterCache.json file for modules not discoverable by Windows PowerShell.

Expected behavior

The cache only includes modules available in Windows PowerShell.

Actual behavior

The module includes PowerShell module paths as well as Windows PowerShell paths.

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
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

3.0.0

Visuals

No response

@michaeltlombardi michaeltlombardi added Issue-Bug Something isn't working Need-Review labels Mar 17, 2025
@Gijsreyn
Copy link
Contributor

Gijsreyn commented Mar 17, 2025

I'm just guessing in the dark here a bit. I was looking at the code, and I think the main responsible commands are:

$DscResources = Get-DscResource
$Modules = Get-Module -ListAvailable

With a combination of the $env:PSModulePath. Strangely enough, I couldn't reproduce the issue on my Windows 10 machine, whereas with Windows 11, I could. I went through the docs, but couldn't find anything strange. However, inspecting the $env:PSModulePath in a Windows PowerShell session on my Win11, revealed the C:\Program Files\PowerShell added. On my Win10, it wasn't.

Strange? Yes. A bug? Maybe...

EDIT 1: Found the following issue on PowerShell repo that might be related

@JohnMcPMS
Copy link
Collaborator

This is affecting our ability to use PowerShellGet/PSModule. @Gijsreyn comment made me check, and on the same machine, running dsc resource list -a <adapter> output contained PowerShellGet:

Shell Adapter Microsoft.Windows/WindowsPowerShell Adapter Microsoft.DSC/PowerShell
Windows PowerShell
PowerShell 7

The DSC resources are only in 2.2.5, not the 1.0.0.1 that is in Windows PowerShell by default. I wonder if the adapter sees that there is a Windows PowerShell module and lets it win despite the resources not actually being present there...

[--- Windows PowerShell ---]
> get-module powershellget -ListAvailable


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

[--- PowerShell 7 ---]
> get-module powershellget -ListAvailable

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Modu…

@SteveL-MSFT
Copy link
Member

I think what I'll do is in the winps adapter, scrub out all ps7 paths in PSModulePath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Need-Review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants