Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class TestClassResource : BaseTestClass
[DscProperty()]
[Ensure] $Ensure

[DscProperty()]
[SecureString] $SecureStringProp

[string] $NonDscProperty # This property shouldn't be in results data

hidden
Expand Down
7 changes: 7 additions & 0 deletions adapters/powershell/Tests/powershellgroup.resource.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
10 changes: 7 additions & 3 deletions adapters/powershell/psDscAdapter/psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
}
Expand Down