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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
for variable values, type comparisons, and internal diagnostics.
- Comparison result still uses `Write-Verbose` to provide user-actionable
information about parameter state differences.
- Use ArrayList and not fixed size array.
- Remove some ForEach-Object usage.
- `Test-ModuleExist`
- Changed module filtering messages from `Write-Verbose` to `Write-Debug`
for internal implementation details.
Expand All @@ -23,11 +25,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed operating system SKU diagnostic message from `Write-Verbose` to `Write-Debug`.
- `Find-Certificate`
- Changed certificate filter diagnostic message from `Write-Verbose` to `Write-Debug`.
- Use ArrayList and not fixed size array.
- `Get-LocalizedDataForInvariantCulture`
- Changed file processing message from `Write-Verbose` to `Write-Debug`
for internal diagnostic information.
- Localized hardcoded `Write-Debug` messages to use localized strings
([#169](https://github.com/dsccommunity/DscResource.Common/issues/169)).
- `Clear-ZeroedEnumPropertyValue`
- Add begin, end blocks.
- `Test-DscPropertyState`
- Use ArrayList and not fixed size array.
- `Assert-BoundParameter`
- Fix PSSA warning.
- `ConvertFrom-DscResourceInstance`
- Fix PSSA warning.
- `Get-DscProperty`
- Use ArrayList and not fixed size array.
- Fix PSSA warning.
- `Remove-CommonParameter`
- Remove use of `Where-Object` and `ForEach-Object`.

### Fixed

Expand Down
8 changes: 7 additions & 1 deletion source/Private/Clear-ZeroedEnumPropertyValue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ function Clear-ZeroedEnumPropertyValue
$InputObject
)

process
begin
{
$result = @{}
}

process
{
foreach ($property in $InputObject.Keys)
{
$value = $InputObject.$property
Expand All @@ -41,7 +44,10 @@ function Clear-ZeroedEnumPropertyValue

$result.$property = $value
}
}

end
{
return $result
}
}
68 changes: 26 additions & 42 deletions source/Private/Test-DscPropertyState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ function Test-DscPropertyState
}
elseif (
$Values.DesiredValue -is [Microsoft.Management.Infrastructure.CimInstance[]] `
-or $Values.DesiredValue -is [System.Array] -and $Values.DesiredValue[0] -is [Microsoft.Management.Infrastructure.CimInstance]
-or $Values.DesiredValue -is [System.Array] -and $Values.DesiredValue[0] -is [Microsoft.Management.Infrastructure.CimInstance]
)
{
if (-not $Values.ContainsKey('KeyProperties'))
{
$errorMessage = $script:localizedData.KeyPropertiesMissing

New-InvalidOperationException -Message $errorMessage
New-InvalidOperationException -Message $script:localizedData.KeyPropertiesMissing
}

$propertyState = @()
$propertyState = [System.Collections.ArrayList]::new()

<#
It is a collection of CIM instances, then recursively call
Expand All @@ -80,23 +78,20 @@ function Test-DscPropertyState

if ($currentCimInstance.Count -gt 1)
{
$errorMessage = $script:localizedData.TooManyCimInstances

New-InvalidOperationException -Message $errorMessage
New-InvalidOperationException -Message $script:localizedData.TooManyCimInstances
}

if ($currentCimInstance)
{
$keyCimInstanceProperties = $currentCimInstance.CimInstanceProperties |
Where-Object -FilterScript {
$keyCimInstanceProperties = $currentCimInstance.CimInstanceProperties.Where({
$_.Name -in $Values.KeyProperties
}
})

<#
For each key property build a string representation of the
property name and its value.
#>
$keyPropertyValues = $keyCimInstanceProperties.ForEach({'{0}="{1}"' -f $_.Name, ($_.Value -join ',')})
$keyPropertyValues = $keyCimInstanceProperties.ForEach({ '{0}="{1}"' -f $_.Name, ($_.Value -join ',') })

Write-Debug -Message (
$script:localizedData.TestingCimInstance -f @(
Expand All @@ -107,16 +102,15 @@ function Test-DscPropertyState
}
else
{
$keyCimInstanceProperties = $desiredCimInstance.CimInstanceProperties |
Where-Object -FilterScript {
$keyCimInstanceProperties = $desiredCimInstance.CimInstanceProperties.Where({
$_.Name -in $Values.KeyProperties
}
})

<#
For each key property build a string representation of the
property name and its value.
#>
$keyPropertyValues = $keyCimInstanceProperties.ForEach({'{0}="{1}"' -f $_.Name, ($_.Value -join ',')})
$keyPropertyValues = $keyCimInstanceProperties.ForEach({ '{0}="{1}"' -f $_.Name, ($_.Value -join ',') })

Write-Debug -Message (
$script:localizedData.MissingCimInstance -f @(
Expand All @@ -138,7 +132,7 @@ function Test-DscPropertyState
}
elseif ($Values.DesiredValue -is [Microsoft.Management.Infrastructure.CimInstance])
{
$propertyState = @()
$propertyState = [System.Collections.ArrayList]::new()

<#
It is a CIM instance, recursively call Test-DscPropertyState for each
Expand Down Expand Up @@ -186,21 +180,21 @@ function Test-DscPropertyState
{
Write-Debug -Message $script:localizedData.ArrayDoesNotMatch

$arrayCompare |
ForEach-Object -Process {
if ($_.SideIndicator -eq '=>')
{
Write-Debug -Message (
$script:localizedData.ArrayValueIsAbsent -f $_.InputObject
)
}
else
{
Write-Debug -Message (
$script:localizedData.ArrayValueIsPresent -f $_.InputObject
)
}
foreach ($item in $arrayCompare)
{
if ($item.SideIndicator -eq '=>')
{
Write-Debug -Message (
$script:localizedData.ArrayValueIsAbsent -f $item.InputObject
)
}
else
{
Write-Debug -Message (
$script:localizedData.ArrayValueIsPresent -f $item.InputObject
)
}
}

$returnValue = $false
}
Expand All @@ -215,17 +209,7 @@ function Test-DscPropertyState

$returnValue = $false

$supportedTypes = @(
'String'
'Int32'
'UInt32'
'Int16'
'UInt16'
'Single'
'Boolean'
)

if ($desiredType.Name -notin $supportedTypes)
if ($desiredType.Name -notin 'String', 'Int32', 'UInt32', 'Int16', 'UInt16', 'Single', 'Boolean')
{
Write-Warning -Message ($script:localizedData.UnableToCompareType -f $desiredType.Name)
}
Expand Down
1 change: 1 addition & 0 deletions source/Public/Assert-BoundParameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#>
function Assert-BoundParameter
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
[CmdletBinding()]
param
(
Expand Down
Loading