Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
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
@@ -0,0 +1,88 @@
$VerbosePreference = 'SilentlyContinue'
$InformationPreference = 'SilentlyContinue'
$ProgressPreference = 'Continue'
$ErrorActionPreference = 'SilentlyContinue'

function Get-TargetResource {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
[OutputType([Hashtable])]
param (
[Parameter(Mandatory)]
[string] $Name,

[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential
)
Write-Verbose "[GET] Get Function running"
return @{
Name = $Name
Credential = $Credential
}

}

function Test-TargetResource {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
[OutputType([System.Boolean])]
param (
[Parameter(Mandatory)]
[string] $Name,

[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential

)
Write-Verbose "[TEST]Checking credentials"
Write-Verbose "[TEST]Checking credentials UserName: $($Credential.UserName)"
Write-Verbose "[TEST]Checking credentials Password: $($Credential.Password)"

if ($null -eq $Credential) {
throw 'Credential property is required'
$inDesiredState = $false
return $false
}

if ($Credential.UserName -ne 'MyUser') {
throw 'Invalid user name'
$inDesiredState = $false
} else {
$inDesiredState = $true
}


return $inDesiredState

}

function Set-TargetResource {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string] $Name,

[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential

)

if ($null -eq $Credential) {
throw 'Credential property is required'
$inDesiredState = $false
return $false
}

if ($Credential.UserName -ne 'MyUser') {
throw 'Invalid user name'
$inDesiredState = $false
} else {
$inDesiredState = $true
}


return $inDesiredState
Write-Verbose "[SET]Credential cannot be remediated by DSC."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ClassVersion("1.0.0.0"), FriendlyName("CredentialValidation")]
class CredentialValidation : OMI_BaseResource
{
[Key] string Name;
[Required, Description("Test Credentials for Script Base"), EmbeddedInstance("MSFT_Credential")] String Credential;
};
62 changes: 62 additions & 0 deletions adapters/powershell/Tests/TestScriptBaseDSC/TestScriptBaseDSC.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@{
# Script module or binary module file associated with this manifest.
RootModule = 'TestScriptBaseDSC.psm1'

# Version number of this module.
moduleVersion = '0.0.1'

# ID used to uniquely identify this module
GUID = 'c3775be8-84a1-43f5-a99c-1b9f2d6bc178'

# Author of this module
Author = ''

# Company or vendor of this module
CompanyName = ''

# Copyright statement for this module
Copyright = ''

# Description of the functionality provided by this module
Description = ''

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'

# Cmdlets to export from this module
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = @()

# Aliases to export from this module
AliasesToExport = @()

# Dsc Resources to export from this module
DscResourcesToExport = @('CredentialValidation')

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource')

# A URL to the license for this module.
LicenseUri = ''

# A URL to the main website for this project.
ProjectUri = ''

# A URL to an icon representing this module.
IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = ''

# Set to a prerelease string value if the release should be a prerelease.
Prerelease = ''
} # End of PSData hashtable
} # End of PrivateData hashtable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Root module for CredentialValidationDsc
# No code required
29 changes: 29 additions & 0 deletions adapters/powershell/Tests/class_ps_resources_secret.dsc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
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: Working with classic DSC resources
type: Microsoft.DSC/PowerShell
properties:
resources:
- name: Class-resource Info
type: TestClassResource/TestClassResource
properties:
Name: TestClassResource1
Prop1: ValueForProp1
Credential: "[parameters('cred')]"
- name: SecureObject
type: Microsoft.DSC.Debug/Echo
properties:
output: "[parameters('cred')]"
showSecrets: "[parameters('showSecrets')]"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
cred:
username: admin
password: {To be Ovveride}
25 changes: 17 additions & 8 deletions adapters/powershell/Tests/powershellgroup.config.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,28 @@ Describe 'PowerShell adapter resource tests' {
It 'Config works with credential object' {
$yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
Credential:
type: secureObject
defaultValue:
username: User
password: Password
resources:
- name: Class-resource Info
type: TestClassResource/TestClassResource
- name: Working with classic DSC resources
type: Microsoft.DSC/PowerShell
properties:
Name: 'TestClassResource'
Credential:
UserName: 'User'
Password: 'Password'
resources:
- name: Class-resource Info
type: TestClassResource/TestClassResource
properties:
Name: TestClassResource1
Prop1: ValueForProp1
Credential: "[parameters('Credential')]"
"@
$out = dsc config get -i $yaml | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.results.result.actualstate.Credential.UserName | Should -Be 'User'
$out.results.result.actualState.result.Credential.Password.Length | Should -Not -BeNullOrEmpty
$out.results.result.actualstate.result.properties.Credential.UserName | Should -Be 'User'
$out.results.result.actualState.result.properties.Credential.Password.Length | Should -Not -BeNullOrEmpty
}

It 'Config does not work when credential properties are missing required fields' {
Expand Down
20 changes: 20 additions & 0 deletions adapters/powershell/Tests/script_ps_resources_secret.dsc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
cred:
type: secureObject
defaultValue:
username: MyUser
password: Password
resources:
- name: Working with classic DSC resources
type: Microsoft.Windows/WindowsPowerShell
properties:
resources:
- name: Script-resource Info
type: TestScriptBaseDSC/CredentialValidation
properties:
Name: TestScriptResource1
Credential: "[parameters('cred')]"
Loading