Skip to content

Commit d9ccec4

Browse files
committed
Debug PSDesiredStateConfiguration
1 parent 85f237b commit d9ccec4

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

build.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,12 @@ if ($Test) {
579579
(Get-Module -Name Pester -ListAvailable).Path
580580
}
581581

582-
Invoke-Pester -Output Detailed -ErrorAction Stop
582+
if ($IsWindows) {
583+
$file = Get-ChildItem -Filter win_powershell.tests.ps1 -Recurse
584+
Invoke-Pester -Path $file -Output Detailed -ErrorAction Stop
585+
} else {
586+
Invoke-Pester -Output Detailed -ErrorAction Stop
587+
}
583588
}
584589

585590
function Find-MakeAppx() {

extensions/powershell/convertDscResource.psm1

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
$Script:IsPowerShellCore = $PSVersionTable.PSEdition -eq 'Core'
2+
3+
if ($Script:IsPowerShellCore)
4+
{
5+
if ($IsWindows)
6+
{
7+
Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion 1.1 -UseWindowsPowerShell -WarningAction SilentlyContinue
8+
}
9+
Import-Module -Name 'PSDesiredStateConfiguration' -MinimumVersion 2.0.7 -Prefix 'Pwsh'
10+
}
11+
112
function Write-DscTrace {
213
param(
314
[Parameter(Mandatory = $false)]
@@ -100,12 +111,12 @@ function ConvertTo-DscObject
100111

101112
(Get-Module -Name 'PSDesiredStateConfiguration' -ListAvailable | ConvertTo-Json) | Write-DscTrace Debug
102113

103-
# Load the PSDesiredStateConfiguration module
104-
Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion '1.1' -Force -ErrorAction stop -ErrorVariable $importModuleError
105-
if (-not [string]::IsNullOrEmpty($importModuleError)) {
106-
'Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace -Operation Error
107-
exit 1
108-
}
114+
# # Load the PSDesiredStateConfiguration module
115+
# Import-Module -Name 'PSDesiredStateConfiguration' -RequiredVersion '1.1' -Force -ErrorAction stop -ErrorVariable $importModuleError
116+
# if (-not [string]::IsNullOrEmpty($importModuleError)) {
117+
# 'Could not import PSDesiredStateConfiguration 1.1 in Windows PowerShell. ' + $importModuleError | Write-DscTrace -Operation Error
118+
# exit 1
119+
# }
109120

110121
# Remove the module version information.
111122
$start = $Content.ToLower().IndexOf('import-dscresource')

extensions/powershell/win_powershell.tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ BeforeDiscovery {
1111

1212
Describe 'PowerShell extension tests' {
1313
It 'Example PowerShell file should work' -Skip:(!$IsWindows -or !$isElevated) {
14+
Write-Verbose -Message $env:PSModulePath -Verbose
15+
16+
$names = Get-ChildItem "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules" | ForEach-Object {Write-Verbose "Found module: $($_.Name)"} -Verbose
17+
1418
$psFile = Resolve-Path -Path "$PSScriptRoot\..\..\dsc\examples\variable.dsc.ps1"
1519
$out = dsc -l trace config get -f $psFile 2>$TestDrive/error.log | ConvertFrom-Json
1620
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)

0 commit comments

Comments
 (0)