functions/set-d365rsatconfiguration.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

<#
    .SYNOPSIS
        Set different RSAT configuration values
         
    .DESCRIPTION
        Update different RSAT configuration values while using the tool
         
    .PARAMETER LogGenerationEnabled
        Will set the LogGeneration property
         
        $true will make RSAT start generating logs
        $false will stop RSAT from generating logs
         
    .PARAMETER VerboseSnapshotsEnabled
        Will set the VerboseSnapshotsEnabled property
         
        $true will make RSAT start generating snapshots and store related details
        $false will stop RSAT from generating snapshots and store related details
         
    .PARAMETER AddOperatorFieldsToExcelValidationEnabled
        Will set the AddOperatorFieldsToExcelValidation property
         
        $true will make RSAT start adding the operation options in the excel parameter file
        $false will stop RSAT from adding the operation options in the excel parameter file
         
    .EXAMPLE
        PS C:\> Set-D365RsatConfiguration -LogGenerationEnabled $true
         
        This will enable the log generation logic of RSAT.
         
    .EXAMPLE
        PS C:\> Set-D365RsatConfiguration -VerboseSnapshotsEnabled $true
         
        This will enable the snapshot generation logic of RSAT.
         
    .EXAMPLE
        PS C:\> Set-D365RsatConfiguration -AddOperatorFieldsToExcelValidationEnabled $true
         
        This will enable the operator generation logic of RSAT.
         
    .NOTES
        Tags: RSAT, Testing, Regression Suite Automation Test, Regression, Test, Automation, Configuration
         
        Author: Mötz Jensen (@Splaxi)
#>


function Set-D365RsatConfiguration {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]

    [CmdletBinding()]
    [OutputType()]
    param (
        [Parameter(Mandatory = $false)]
        [bool] $LogGenerationEnabled,

        [Parameter(Mandatory = $false)]
        [bool] $VerboseSnapshotsEnabled,

        [Parameter(Mandatory = $false)]
        [bool] $AddOperatorFieldsToExcelValidationEnabled
    )

    $configPath = Join-Path $Script:RsatPath "Microsoft.Dynamics.RegressionSuite.WindowsApp.exe.config"

    if (-not (Test-PathExists -Path $configPath -Type Leaf)) {
        Write-PSFMessage -Level Critical -Message "The 'Microsoft.Dynamics.RegressionSuite.WindowsApp.exe.config' file could not be found on the system."
        Stop-PSFFunction -Message  "Stopping because the 'Microsoft.Dynamics.RegressionSuite.WindowsApp.exe.config' file could not be located."
        return
    }

    try {
        [xml]$xmlConfig = Get-Content $configPath

        if ($PSBoundParameters.Keys -contains "LogGenerationEnabled") {
            $logGenerationAttribute = $xmlConfig.SelectNodes('//appSettings//add[@key="LogGeneration"]')
            $logGenerationAttribute.SetAttribute('value', $LogGenerationEnabled.ToString().ToLower())
        }

        if ($PSBoundParameters.Keys -contains "VerboseSnapshotsEnabled") {
            $verboseSnapshotsAttribute = $xmlConfig.SelectNodes('//appSettings//add[@key="VerboseSnapshotsEnabled"]')
            $verboseSnapshotsAttribute.SetAttribute('value', $VerboseSnapshotsEnabled.ToString().ToLower())
        }

        if ($PSBoundParameters.Keys -contains "AddOperatorFieldsToExcelValidationEnabled") {
            $addOperatorFieldsToExcelValidationAttribute = $xmlConfig.SelectNodes('//appSettings//add[@key="AddOperatorFieldsToExcelValidation"]')
            $addOperatorFieldsToExcelValidationAttribute.SetAttribute('value', $AddOperatorFieldsToExcelValidationEnabled.ToString().ToLower())
        }

        $xmlConfig.Save($configPath)
    }
    catch {
        Write-PSFMessage -Level Host -Message "Something went wrong while updating the RSAT configuration file" -Exception $PSItem.Exception
        Stop-PSFFunction -Message "Stopping because of errors"
        return
    }
}