Module/Rule.VsphereAdvancedSettings/Convert/Methods.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#region Method Functions

<#
    .SYNOPSIS
        Takes the AdvancedSettings property from a VsphereAdvancedSettingsRule.
 
    .PARAMETER RawString
        An array of the raw string data taken from the Fix Text of the STIG.
 
    .PARAMETER CheckContent
        An array of the raw string data taken from the STIG setting.
#>

function Get-VsphereAdvancedSettings
{
    [CmdletBinding()]
    [OutputType([object])]
    param
    (
        [Parameter(Mandatory = $true)]
        [psobject]
        $FixText,

        [Parameter()]
        [psobject]
        $CheckContent
    )

    if ($FixText -match 'Get-AdvancedSetting')
    {
        $matchName = ($FixText | Select-String -Pattern '(?<=Get-AdvancedSetting -Name )([^\s]+)' -AllMatches).Matches.Value
        $matchValue = ($FixText | Select-String -Pattern '(?<=Set-AdvancedSetting -Value |Set-AdvancedSetting -Value ")[^"]+' -AllMatches).Matches.Value
        $advancedSettings = "'{0}' = '{1}'" -f $matchName, $matchValue
    }

    switch ($matchName)
    {
        {$PSItem -eq "Annotations.WelcomeMessage"}
        {
            $matchValue = ($CheckContent | Select-String -Pattern 'You are accessing[^"]+(?<=details.)').Matches.Value
            $advancedSettings = "'{0}' = '{1}'" -f $matchName,$matchValue
        }
        {$PSItem -eq "Config.Etc.issue"}
        {
            $matchValue = ($CheckContent | Select-String -Pattern 'You are accessing[^"]+').Matches.Value
            $advancedSettings = "'{0}' = '{1}'" -f $matchName,$matchValue
        }
        {$PSItem -eq "Net.DVFilterBindIpAddress"}
        {
            $advancedSettings = "'{0}' = ''" -f $matchName
        }
        {$PSItem -match "Syslog.global.logHost|Config.HostAgent.plugins.hostsvc.esxAdminsGroup|Syslog.global.logDir"}
        {
            $advancedSettings = $null
        }
    }

    if ($null -ne $advancedSettings)
    {
        Write-Verbose -Message $("[$($MyInvocation.MyCommand.Name)] Found Advanced Setting: {0}" -f $advancedSettings)
        return $advancedSettings
    }
    else
    {
        return $null
    }
}

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

    switch ($Id)
    {
        {$PsItem -match 'V-93955|V-207605'}
        {
            return '{0} is set to "Syslog.global.logHost" = "site specific log host"'
        }
        {$PsItem -match 'V-94037|V-207646'}
        {
            return '"{0}" is set to "Syslog.global.logDir" = "site specific log storage location"'
        }
        default
        {
            return $null
        }
    }
}