Skip to content

Change order for winps-adapter to prefer Windows modules first, add warning when resource not found #764

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

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions powershell-adapter/psDscAdapter/win_psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading