Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
61f4b85
Add to win_psDscAdapter function for extraxting string from PSCredent…
mimachniak Dec 8, 2025
cd5df41
Add to win_psDscAdapter for ScriptBase resources PSCredentails fix co…
mimachniak Dec 8, 2025
98e7099
Merge branch 'PowerShell:main' into win_psDscAdapter-PSCredentials-fi…
mimachniak Dec 17, 2025
0a7c6aa
Fix win_psDscAdapter for ScriptBase resources PSCredentails fix conve…
mimachniak Dec 18, 2025
82aeec4
psDscAdapter for ClassBase resources PSCredentails fix convert to Sys…
mimachniak Dec 18, 2025
506ba9f
Add for testClass testing yaml with secureObject - main file and para…
mimachniak Dec 18, 2025
49c381c
Fix win_psDscAdapter for ClassBase resources PSCredentails fix conver…
mimachniak Dec 18, 2025
403e6b5
Fix win_psDscAdapter for ClassBase resources PSCredentails fix conver…
mimachniak Dec 18, 2025
352dd69
Ad unit test for credentaials in powershellgroup.config.tests.ps1 - v…
mimachniak Dec 21, 2025
4af004e
Ad unit test for credentaials in win_powershellgroup.tests.ps1 - vali…
mimachniak Dec 22, 2025
dd7425e
Ad unit test for credentaials in win_powershellgroup.tests.ps1 - vali…
mimachniak Dec 22, 2025
b8cff4a
Add script base DSC resources for testing credentials
mimachniak Jan 11, 2026
63cd935
Add script base DSC resources for testing credentials and fix win_PsD…
mimachniak Jan 12, 2026
73dacde
Script base yaml DSC resources for credential valid
mimachniak Jan 12, 2026
34b6b73
Add script base resource test in win_powershellgroup.tests.ps1
mimachniak Jan 13, 2026
877ee8b
Add to win_psDscAdapter.psm1 support for secure object and test value…
mimachniak Jan 13, 2026
7984d06
Add to psDscAdapter.psm1 support for secure object and test value par…
mimachniak Jan 13, 2026
661259b
Change faild test win_powershellgroup.tests it false
mimachniak Jan 13, 2026
f6b366e
Add to psDscAdapter.psm1 remove output of credntials
mimachniak Jan 15, 2026
6763c23
Remove spaces
mimachniak Jan 15, 2026
779e259
Add to psDscAdapter.psm1 remove output of credntials
mimachniak Jan 15, 2026
2d10057
Add to unit test for PowerShell adapter in verions 5.1
mimachniak Jan 15, 2026
3c57cf8
Fix test file parsing
mimachniak Jan 21, 2026
3542591
Fix DSC - test and class path creation for subfolder
mimachniak Jan 21, 2026
4400c8f
Run test
mimachniak Jan 22, 2026
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
48 changes: 48 additions & 0 deletions adapters/powershell/Tests/win_powershell_script_resources.dsc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
SafemodeAdministratorPassword:
type: string
showSecrets:
type: bool
defaultValue: true
cred:
type: secureObject
metadata:
Microsoft.DSC:
requiredSecurityContext: elevated # this is the default and just used as an example indicating this config works for admins and non-admins
resources:
- name: Use class PowerShell resources
type: Microsoft.Windows/WindowsPowerShell
properties:
resources:
- name: Windows Features Install ADS
type: PSDesiredStateConfiguration/WindowsFeature
properties:
ensure: Present
name: AD-Domain-Services
- name: Windows Features Install ADS RSAT
type: PSDesiredStateConfiguration/WindowsFeature
properties:
ensure: Present
name: RSAT-AD-PowerShell
dependsOn:
- "[resourceId('PSDesiredStateConfiguration/WindowsFeature','Windows Features Install ADS')]"
- name: Active Directory Forest
type: ActiveDirectoryDsc/ADDomain
properties:
DomainName: contoso.com
Credential:
Username: "[parameters('cred').username]"
Password: "[parameters('cred').password]"
SafemodeAdministratorPassword:
Username: "[parameters('cred').username]"
Password: "[parameters('cred').password]"
ForestMode: WinThreshold
- name: secureObject
type: Microsoft.DSC.Debug/Echo
properties:
output: "[parameters('cred')]"
showSecrets: "[parameters('showSecrets')]"
36 changes: 35 additions & 1 deletion adapters/powershell/psDscAdapter/win_psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,36 @@ function Get-DscResourceObject {
return $desiredState
}

## Primitive value for PScredentials

function Get-PrimitiveValueString {
param([Parameter(Mandatory)][object]$Value)

# If already a string → done
if ($Value -is [string]) {
return $Value
}

# If it's a hashtable or PSCustomObject → unwrap
if ($Value -is [hashtable] -or $Value -is [pscustomobject]) {
$props = $Value.psobject.Properties

# Case 1: { secureString = "admin" }
if ($props.Name -contains 'secureString') {
return $Value.secureString
}

# Case 2: nested object e.g. @{ value = @{ secureString = "admin" }}
if ($props.Count -eq 1) {
return Get-PrimitiveValueString $props.Value
}

"Cannot extract primitive value from nested object: $($Value | Out-String)" | Write-DscTrace -Operation Error
}

"Unsupported type '$($Value.GetType().FullName)' for primitive extraction" | Write-DscTrace -Operation Error
}

# Get the actual state using DSC Get method from any type of DSC resource
function Invoke-DscOperation {
param(
Expand Down Expand Up @@ -368,7 +398,11 @@ function Invoke-DscOperation {
"Credential object '$($_.Name)' requires both 'username' and 'password' properties" | Write-DscTrace -Operation Error
exit 1
}
$property.$($_.Name) = [System.Management.Automation.PSCredential]::new($_.Value.Username, (ConvertTo-SecureString -AsPlainText $_.Value.Password -Force))

$username = Get-PrimitiveValueString $_.Value.Username
$password = $_.Value.Password | ConvertTo-SecureString -AsPlainText -Force
$property.$($_.Name) = [System.Management.Automation.PSCredential]::new($username, $password)

} else {
$property.$($_.Name) = $_.Value.psobject.properties | ForEach-Object -Begin { $propertyHash = @{} } -Process { $propertyHash[$_.Name] = $_.Value } -End { $propertyHash }
}
Expand Down