Public/Basic/Set-BTFunctionLevel.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
function Set-BTFunctionLevel
{
    <#
        .SYNOPSIS
        Changes the function level of the BurntToast module.
         
        .DESCRIPTION
        The Set-BTFunctionLevel function changes the function level of the BurntToast module as defined in config.json.
 
        To use Set-BTFunctionLevel, use the FunctionLevel parameter to identify the desired FunctionLevel. The only valid inputs to the FunctionLevel parameter are 'Basic' and 'Advanced.'
 
        As the confirguration for the BurntToast module is saved into a file, PowerShell must be run as an Administrator in order to set a new function level if the module is saved to a location other than the users' home directory. This function will issue an error if this is the case.
 
        The BurntToast module needs to be re-imported in order for a new function level to take effect and this function will issue a warning when it runs successfully.
         
        .PARAMETER FunctionLevel
        Specifies the function level to set. Valid inputs are 'Basic' and 'Advanced' and 'Basic' is the default option.
 
        .INPUTS
        System.String
 
        You cannot pipe input to this cmdlet.
 
        .OUTPUTS
        None
 
        .NOTES
        The Set-BTFunctionLevel function is classified as: Basic
 
        .EXAMPLE
        Set-BTFunctionLevel
 
        This command changes the function level of the BurntToast module to 'Basic', as the default option, if the current function level is 'Advanced.' If the current function level is already set to 'Basic' the function ends without making a change.
 
        .EXAMPLE
        Set-BTFunctionLevel -FunctionLevel Basic
        This command changes the function level of the BurntToast module to 'Basic' if the current function level is 'Advanced.' If the current function level is already set to 'Basic' the function ends without making a change.
 
        .EXAMPLE
        Set-BTFunctionLevel -FunctionLevel Advanced
 
        This command changes the function level of the BurntToast module to 'Advanced' if the current function level is 'Basic.' If the current function level is already set to 'Advanced' the function ends without making a change.
         
        .LINK
        https://github.com/Windos/BurntToast/blob/master/Help/Set-BTFunctionLevel.md
 
        .LINK
        Get-BTFunctionLevel
    #>


    param
    (
        [Parameter()]
        [ValidateSet('Basic','Advanced')] 
        [string] $FunctionLevel = 'Basic'
    )
    
    $ConfigPath = "$PSScriptRoot\..\..\config.json"
    $CurrentLevel = $Script:Config.FunctionLevel


    if ($CurrentLevel -ne $FunctionLevel)
    {
        $Script:Config.FunctionLevel = $FunctionLevel

        try
        {
        
            $Script:Config | ConvertTo-Json | Out-File -FilePath $ConfigPath -Encoding utf8
            Write-Warning -Message 'Configuration updated, please re-import the BurntToast module or start a new PowerShell session to reflect this function level change.'
        }
        catch
        {
            #TODO: Write/Link to better instructions
            Write-Error -Message "Unable to update $ConfigPath, try running PowerShell as an administrator or moving the BurntToast module to your user directory."
        }
    }
}