Skip to content

Commit 59cd4a7

Browse files
authored
Merge pull request #764 from SteveL-MSFT/psdsc-winps
Change order for winps-adapter to prefer Windows modules first, add warning when resource not found
2 parents 2b2a4f9 + 597b0f5 commit 59cd4a7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if ($PSVersionTable.PSVersion.Major -gt 5) {
2525
$PSDesiredStateConfiguration = Import-Module $m -Force -PassThru
2626
}
2727
else {
28-
$env:PSModulePath += ";$env:windir\System32\WindowsPowerShell\v1.0\Modules"
28+
$env:PSModulePath = "$env:windir\System32\WindowsPowerShell\v1.0\Modules;$env:PSModulePath"
2929
$PSDesiredStateConfiguration = Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion '1.1' -Force -PassThru -ErrorAction stop -ErrorVariable $importModuleError
3030
if (-not [string]::IsNullOrEmpty($importModuleError)) {
3131
'Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace -Operation Error
@@ -392,6 +392,9 @@ function Invoke-DscOperation {
392392
}
393393
catch {
394394
$_.Exception | Format-List * -Force | Out-String | Write-DscTrace -Operation Debug
395+
if ($_.Exception.MessageId -eq 'DscResourceNotFound') {
396+
Write-DscTrace -Operation Warn -Message 'For Windows PowerShell, DSC resources must be installed with scope AllUsers'
397+
}
395398
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
396399
exit 1
397400
}
@@ -446,7 +449,10 @@ function Invoke-DscOperation {
446449
}
447450
}
448451
catch {
449-
452+
$_.Exception | Format-List * -Force | Out-String | Write-DscTrace -Operation Debug
453+
if ($_.Exception.MessageId -eq 'DscResourceNotFound') {
454+
Write-DscTrace -Operation Warn -Message 'For Windows PowerShell, DSC resources must be installed with scope AllUsers'
455+
}
450456
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
451457
exit 1
452458
}

0 commit comments

Comments
 (0)