From dbe6891f4c10cbf8fed39aaa87283269ef902618 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Thu, 24 Apr 2025 16:13:37 -0700 Subject: [PATCH 1/2] Change order for winps-adapter to prefer Windows modules first --- powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 index 3ff1c6803..5dc842fbb 100644 --- a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 +++ b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 @@ -25,7 +25,7 @@ if ($PSVersionTable.PSVersion.Major -gt 5) { $PSDesiredStateConfiguration = Import-Module $m -Force -PassThru } else { - $env:PSModulePath += ";$env:windir\System32\WindowsPowerShell\v1.0\Modules" + $env:PSModulePath = "$env:windir\System32\WindowsPowerShell\v1.0\Modules;$env:PSModulePath" $PSDesiredStateConfiguration = Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion '1.1' -Force -PassThru -ErrorAction stop -ErrorVariable $importModuleError if (-not [string]::IsNullOrEmpty($importModuleError)) { 'Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace -Operation Error From 597b0f5a50cc8aba3606de67b49bb3ad79f41a20 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Fri, 25 Apr 2025 17:11:20 -0700 Subject: [PATCH 2/2] add warning if using winps and module not found --- powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 index 5dc842fbb..8bc9aada3 100644 --- a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 +++ b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 @@ -392,6 +392,9 @@ function Invoke-DscOperation { } catch { $_.Exception | Format-List * -Force | Out-String | Write-DscTrace -Operation Debug + if ($_.Exception.MessageId -eq 'DscResourceNotFound') { + Write-DscTrace -Operation Warn -Message 'For Windows PowerShell, DSC resources must be installed with scope AllUsers' + } 'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error exit 1 } @@ -446,7 +449,10 @@ function Invoke-DscOperation { } } catch { - + $_.Exception | Format-List * -Force | Out-String | Write-DscTrace -Operation Debug + if ($_.Exception.MessageId -eq 'DscResourceNotFound') { + Write-DscTrace -Operation Warn -Message 'For Windows PowerShell, DSC resources must be installed with scope AllUsers' + } 'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error exit 1 }