diff --git a/build.ps1 b/build.ps1 index 9b88b1570..f6f9adab4 100755 --- a/build.ps1 +++ b/build.ps1 @@ -158,6 +158,10 @@ if ($null -ne $packageType) { Remove-Item temp:/rustup-init.exe -ErrorAction Ignore } } + else { + Write-Verbose -Verbose "Rust found, updating..." + & $rustup update + } $BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC" diff --git a/powershell-adapter/Tests/win_powershellgroup.tests.ps1 b/powershell-adapter/Tests/win_powershellgroup.tests.ps1 index e2258888a..2b03a068f 100644 --- a/powershell-adapter/Tests/win_powershellgroup.tests.ps1 +++ b/powershell-adapter/Tests/win_powershellgroup.tests.ps1 @@ -292,6 +292,12 @@ resources: Tags = @( 'PSDscResource_PSClassResource' ) + DscCapabilities = @( + 'get' + 'test' + 'set' + 'export' + ) } } } @@ -303,11 +309,24 @@ resources: $module = @' +enum Ensure { + Present + Absent +} + [DSCResource()] class PSClassResource { [DscProperty(Key)] [string] $Name + [string] $NonDscProperty + + hidden + [string] $HiddenNonDscProperty + + [DscProperty()] + [Ensure] $Ensure = [Ensure]::Present + PSClassResource() { } @@ -333,6 +352,7 @@ class PSClassResource { 1..$resultCount | %{ $obj = New-Object PSClassResource $obj.Name = "Object$_" + $obj.Ensure = [Ensure]::Present $resultList.Add($obj) } @@ -358,6 +378,8 @@ class PSClassResource { $out = dsc resource get -r PSClassResource/PSClassResource --input (@{Name = 'TestName' } | ConvertTo-Json) | ConvertFrom-Json $LASTEXITCODE | Should -Be 0 $out.actualState.Name | Should -Be 'TestName' + $propCount = $out.actualState | Get-Member -MemberType NoteProperty + $propCount.Count | Should -Be 1 # Only the DscProperty should be returned } It 'Set works with class-based PS DSC resources' -Skip:(!$IsWindows) { @@ -373,5 +395,7 @@ class PSClassResource { $LASTEXITCODE | Should -Be 0 $out | Should -Not -BeNullOrEmpty $out.resources.count | Should -Be 5 + $out.resources[0].properties.Ensure | Should -Be 'Present' # Check for enum property } -} \ No newline at end of file +} + diff --git a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 index 6bd1b32dd..a10a940ad 100644 --- a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 +++ b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 @@ -402,6 +402,10 @@ function Invoke-DscOperation { $resource = GetTypeInstanceFromModule -modulename $cachedDscResourceInfo.ModuleName -classname $cachedDscResourceInfo.Name $dscResourceInstance = $resource::New() + $ValidProperties = $cachedDscResourceInfo.Properties.Name + + $ValidProperties | ConvertTo-Json | Write-DscTrace -Operation Trace + if ($DesiredState.properties) { # set each property of $dscResourceInstance to the value of the property in the $desiredState INPUT object $DesiredState.properties.psobject.properties | ForEach-Object -Process { @@ -427,7 +431,16 @@ function Invoke-DscOperation { switch ($Operation) { 'Get' { - $Result = $dscResourceInstance.Get() + $Result = @{} + $raw_obj = $dscResourceInstance.Get() + $ValidProperties | ForEach-Object { + if ($raw_obj.$_ -is [System.Enum]) { + $Result[$_] = $raw_obj.$_.ToString() + } + else { + $Result[$_] = $raw_obj.$_ + } + } $addToActualState.properties = $Result } 'Set' {