Public/New-BTAppId.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
function New-BTAppId
{
    <#
        .SYNOPSIS
        Creates a new AppId Registry Key.
 
        .DESCRIPTION
        The New-BTAppId function create a new AppId registry key in the Current User's Registery Hive. If the desired AppId is already present in the Registry then no changes are made.
 
        If no AppId is specified then the AppId specified in the config.json file in the BurntToast module's root directory is used.
 
        .PARAMETER AppId
        Specifies the new AppId. You can use any alphanumeric characters.
 
        Defaults to the AppId specified in the config.json file in the BurntToast module's root directoy if not provided.
 
        .INPUTS
        System.String
 
        You cannot pipe input to this cmdlet.
 
        .OUTPUTS
        None
 
        .NOTES
        The New-BTAppId function is classified as: Basic
 
        .EXAMPLE
        New-BTAppId
 
        This command creates an AppId registry key using the value specified in the BurntToast module's config.json file, which is 'BurntToast' by default.
 
        .EXAMPLE
        New-BTAppId -AppId 'Script Checker'
 
        This command create an AppId registry key called 'Script Checker.'
         
        .LINK
        https://github.com/Windos/BurntToast/blob/master/Help/New-BTAppId.md
    #>


    [CmdletBinding()]
    param
    (
        [ValidateNotNullOrEmpty()] 
        [string] $AppId = $Script:Config.AppId
    )
    
    $RegPath = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings'
    
    if (!(Test-Path -Path "$RegPath\$AppId"))
    {
        $null = New-Item -Path $RegPath -Name $AppId
        $null = New-ItemProperty -Path "$RegPath\$AppId" -Name 'ShowInActionCenter' -Value 1 -PropertyType 'DWORD'
    }
    else
    {
        Write-Warning -Message 'Specified AppId is already present in the registry.'
    }
}