Module/Common/Convert/Function.Helper.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

<#
    .SYNOPSIS
        Appends the next letter in the alphabet to the ID to handle rules that enforce multiple settings
#>

function Get-AvailableId
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $Id
    )

    $usedId = $global:stigSettings | Where-Object -FilterScript { $PSItem.Id -match $ID } |
            Sort-Object -Property Id

    if ( $null -eq $usedId )
    {
        return $id
    }
    else
    {
        $startInt = 96
        # 97 is the ascii char 'a', lets start with 96 so the second rule with the same id gets appended with a letter

        $appendLetterInt = $startInt + $usedId.count

        return "$id.$([char]$appendLetterInt)"
    }
}