diff --git a/adapters/powershell/Tests/TestClassResource/0.0.1/TestClassResource.psm1 b/adapters/powershell/Tests/TestClassResource/0.0.1/TestClassResource.psm1 index d36757d84..4e0808c8e 100644 --- a/adapters/powershell/Tests/TestClassResource/0.0.1/TestClassResource.psm1 +++ b/adapters/powershell/Tests/TestClassResource/0.0.1/TestClassResource.psm1 @@ -40,6 +40,9 @@ class TestClassResource : BaseTestClass [DscProperty()] [Ensure] $Ensure + [DscProperty()] + [SecureString] $SecureStringProp + [string] $NonDscProperty # This property shouldn't be in results data hidden diff --git a/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 b/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 index 4fd12b4e4..9efd22a72 100644 --- a/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 +++ b/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 @@ -376,4 +376,11 @@ Describe 'PowerShell adapter resource tests' { $LASTEXITCODE | Should -Be 7 Get-Content -Path $TestDrive/error.log | Should -Match 'Resource not found: TestClassResource/TestClassResource 0.0.2' } + + It 'Can process SecureString property' { + $r = '{"Name":"TestClassResource1","SecureStringProp":"MySecretValue"}' | dsc resource get -r 'TestClassResource/TestClassResource' -f - + $LASTEXITCODE | Should -Be 0 + $res = $r | ConvertFrom-Json + $res.actualState.SecureStringProp | Should -Not -BeNullOrEmpty + } } diff --git a/adapters/powershell/psDscAdapter/psDscAdapter.psm1 b/adapters/powershell/psDscAdapter/psDscAdapter.psm1 index 61051beb9..5f1542c84 100644 --- a/adapters/powershell/psDscAdapter/psDscAdapter.psm1 +++ b/adapters/powershell/psDscAdapter/psDscAdapter.psm1 @@ -424,9 +424,9 @@ function Invoke-DscOperation { # set each property of $dscResourceInstance to the value of the property in the $desiredState INPUT object $DesiredState.properties.psobject.properties | ForEach-Object -Process { # handle input objects by converting them to a hash table + $validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name if ($_.Value -is [System.Management.Automation.PSCustomObject]) { - $validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name - if ($validateProperty -and $validateProperty.PropertyType -eq 'PSCredential') { + if ($validateProperty -and $validateProperty.PropertyType -in @('PSCredential', 'System.Management.Automation.PSCredential')) { if (-not $_.Value.Username -or -not $_.Value.Password) { "Credential object '$($_.Name)' requires both 'username' and 'password' properties" | Write-DscTrace -Operation Error exit 1 @@ -438,7 +438,11 @@ function Invoke-DscOperation { } } else { - $dscResourceInstance.$($_.Name) = $_.Value + if ($validateProperty -and $validateProperty.PropertyType -in @('SecureString', 'System.Security.SecureString') -and -not [string]::IsNullOrEmpty($_.Value)) { + $dscResourceInstance.$($_.Name) = ConvertTo-SecureString -AsPlainText $_.Value -Force + } else { + $dscResourceInstance.$($_.Name) = $_.Value + } } } }