@@ -364,7 +364,12 @@ 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
- $property [$_.Name ] = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
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))
369
+ }
370
+ else {
371
+ $property [$_.Name ] = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
372
+ }
368
373
}
369
374
else {
370
375
$property [$_.Name ] = $_.Value
@@ -373,7 +378,7 @@ function Invoke-DscOperation {
373
378
374
379
# using the cmdlet the appropriate dsc module, and handle errors
375
380
try {
376
- Write-DscTrace - Operation Debug - Message " Module: $ ( $cachedDscResourceInfo.ModuleName ) , Name: $ ( $cachedDscResourceInfo.Name ) , Property: $ ( $property ) "
381
+ Write-DscTrace - Operation Debug - Message " Module: $ ( $cachedDscResourceInfo.ModuleName ) , Name: $ ( $cachedDscResourceInfo.Name ) , Property: $ ( $property | ConvertTo-Json - Compress ) "
377
382
$invokeResult = Invoke-DscResource - Method $Operation - ModuleName $cachedDscResourceInfo.ModuleName - Name $cachedDscResourceInfo.Name - Property $property - ErrorAction Stop
378
383
379
384
if ($invokeResult.GetType ().Name -eq ' Hashtable' ) {
@@ -402,7 +407,18 @@ function Invoke-DscOperation {
402
407
if ($DesiredState.properties ) {
403
408
# set each property of $dscResourceInstance to the value of the property in the $desiredState INPUT object
404
409
$DesiredState.properties.psobject.properties | ForEach-Object - Process {
405
- $dscResourceInstance .$ ($_.Name ) = $_.Value
410
+ # handle input objects by converting them to a hash table
411
+ if ($_.Value -is [System.Management.Automation.PSCustomObject ]) {
412
+ if ($_.Name -like ' *Credential*' -and $_.Value.Username -and $_.Value.Password ) {
413
+ $dscResourceInstance .$ ($_.Name ) = [System.Management.Automation.PSCredential ]::new($_.Value.Username , (ConvertTo-SecureString - AsPlainText $_.Value.Password - Force))
414
+ }
415
+ else {
416
+ $dscResourceInstance .$ ($_.Name ) = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
417
+ }
418
+ }
419
+ else {
420
+ $dscResourceInstance .$ ($_.Name ) = $_.Value
421
+ }
406
422
}
407
423
}
408
424
@@ -444,9 +460,23 @@ function Invoke-DscOperation {
444
460
}
445
461
446
462
# morph the INPUT object into a hashtable named "property" for the cmdlet Invoke-DscResource
447
- $DesiredState.properties.psobject.properties | ForEach-Object - Begin { $property = @ {} } - Process { $property [$_.Name ] = $_.Value }
463
+ $DesiredState.properties.psobject.properties | ForEach-Object - Begin { $property = @ {} } - Process {
464
+ 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))
467
+ }
468
+ else {
469
+ $property [$_.Name ] = $_.Value.psobject.properties | ForEach-Object - Begin { $propertyHash = @ {} } - Process { $propertyHash [$_.Name ] = $_.Value } - End { $propertyHash }
470
+ }
471
+ }
472
+ else {
473
+ $property [$_.Name ] = $_.Value
474
+ }
475
+ }
476
+
448
477
# using the cmdlet from PSDesiredStateConfiguration module in Windows
449
478
try {
479
+ Write-DscTrace - Operation Debug - Message " Module: $ ( $cachedDscResourceInfo.ModuleName ) , Name: $ ( $cachedDscResourceInfo.Name ) , Property: $ ( $property | ConvertTo-Json - Compress) "
450
480
$invokeResult = Invoke-DscResource - Method $Operation - ModuleName $cachedDscResourceInfo.ModuleName - Name $cachedDscResourceInfo.Name - Property $property
451
481
if ($invokeResult.GetType ().Name -eq ' Hashtable' ) {
452
482
$invokeResult.keys | ForEach-Object - Begin { $ResultProperties = @ {} } - Process { $ResultProperties [$_ ] = $invokeResult .$_ }
0 commit comments