Class-based resources in Windows PowerShell not found when called from PowerShell
Prerequisites
- [x] Write a descriptive title.
- [x] Make sure you are able to repro it on the latest version
- [x] Search the existing issues.
Summary
Install a class-based DSC resource module into the current user path ~\Documents\WindowsPowerShell\Modules\ are not found by Microsoft.Windows/WindowsPowerShell adapter when called from PowerShell 7, if called from Windows PowerShell the resources are returned as expected. All users path works as expected in both PowerShell and Windows PowerShell.
Steps to reproduce
- Install class-based DSC resource into current users path
- In PowerShell 7 execute
dsc resource list --adapter Microsoft.Windows/WindowsPowerShell
Expected behavior
Current user PS module path DSC resources should be found.
Actual behavior
Current user PS module path DSC resources are not found.
Error details
Environment data
7.6-preview4
Version
3.1.0-preview.5
Visuals
No response
@ThomasNieto when the adapter is invoked, it prints out PSModulePath to debug level. https://github.com/PowerShell/DSC/blob/47c0d4fc61affb61547bdcf4cd250a80aa29f717/powershell-adapter/psDscAdapter/powershell.resource.ps1#L28
You'll find the paths are not the same for Windows PowerShell and PowerShell 7. Switching between the two will lead to stale paths to be detected, triggering a cache refresh.
The win_psDscAdapter adapter also needs a workaround from #797 to assign ClassBased to ImplementationDetail or you will not trigger the ClassBased branch in Invoke-DscOperation.
Unfortunately, the workaround has a bug and will incorrectly assign ClassBased to MOF resources like PSDesiredStateConfiguration/Environment and ComputerManagementDsc/TimeZone.