@@ -364,11 +364,16 @@ function Invoke-DscOperation {
364
364
# morph the INPUT object into a hashtable named "property" for the cmdlet Invoke-DscResource
365
365
$DesiredState.properties.psobject.properties | ForEach-Object - Begin { $property = @ {} } - Process {
366
366
if ($_.Value -is [System.Management.Automation.PSCustomObject ]) {
367
- if ($_.Name -like ' *Credential*' -and $_.Value.Username -and $_.Value.Password ) {
368
- $property [$_.Name ] = [System.Management.Automation.PSCredential ]::new($_.Value.Username , (ConvertTo-SecureString - AsPlainText $_.Value.Password - Force))
367
+ $validateProperty = $cachedDscResourceInfo.Properties | Where-Object - Property Name -EQ $_.Value
368
+ if ($validateProperty.PropertyType -eq ' PSCredential' ) {
369
+ if (-not $_.Value.Username -and -not $_.Value.Password ) {
370
+ " Credential property '$ ( $_.Name ) ' requires both username and password input object" | Write-DscTrace - Operation Error
371
+ exit 1
372
+ }
373
+ $dscResourceInstance .$ ($_.Name ) = [System.Management.Automation.PSCredential ]::new($_.Value.Username , (ConvertTo-SecureString - AsPlainText $_.Value.Password - Force))
369
374
}
370
375
else {
371
- $property [ $ _.Name ] = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
376
+ $dscResourceInstance . $ ( $ _.Name ) = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
372
377
}
373
378
}
374
379
else {
@@ -409,7 +414,12 @@ function Invoke-DscOperation {
409
414
$DesiredState.properties.psobject.properties | ForEach-Object - Process {
410
415
# handle input objects by converting them to a hash table
411
416
if ($_.Value -is [System.Management.Automation.PSCustomObject ]) {
412
- if ($_.Name -like ' *Credential*' -and $_.Value.Username -and $_.Value.Password ) {
417
+ $validateProperty = $cachedDscResourceInfo.Properties | Where-Object - Property Name -EQ $_.Value
418
+ if ($validateProperty.PropertyType -eq ' PSCredential' ) {
419
+ if (-not $_.Value.Username -and -not $_.Value.Password ) {
420
+ " Credential property '$ ( $_.Name ) ' requires both username and password input object" | Write-DscTrace - Operation Error
421
+ exit 1
422
+ }
413
423
$dscResourceInstance .$ ($_.Name ) = [System.Management.Automation.PSCredential ]::new($_.Value.Username , (ConvertTo-SecureString - AsPlainText $_.Value.Password - Force))
414
424
}
415
425
else {
@@ -462,11 +472,16 @@ function Invoke-DscOperation {
462
472
# morph the INPUT object into a hashtable named "property" for the cmdlet Invoke-DscResource
463
473
$DesiredState.properties.psobject.properties | ForEach-Object - Begin { $property = @ {} } - Process {
464
474
if ($_.Value -is [System.Management.Automation.PSCustomObject ]) {
465
- if ($_.Name -Like ' *Credential*' -and $_.Value.Username -and $_.Value.Password ) {
466
- $property [$_.Name ] = [System.Management.Automation.PSCredential ]::new($_.Value.Username , (ConvertTo-SecureString - AsPlainText $_.Value.Password - Force))
475
+ $validateProperty = $cachedDscResourceInfo.Properties | Where-Object - Property Name -EQ $_.Value
476
+ if ($validateProperty.PropertyType -eq ' PSCredential' ) {
477
+ if (-not $_.Value.Username -and -not $_.Value.Password ) {
478
+ " Credential property '$ ( $_.Name ) ' requires both username and password input object" | Write-DscTrace - Operation Error
479
+ exit 1
480
+ }
481
+ $dscResourceInstance .$ ($_.Name ) = [System.Management.Automation.PSCredential ]::new($_.Value.Username , (ConvertTo-SecureString - AsPlainText $_.Value.Password - Force))
467
482
}
468
483
else {
469
- $property [ $ _.Name ] = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
484
+ $dscResourceInstance . $ ( $ _.Name ) = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
470
485
}
471
486
}
472
487
else {
0 commit comments