Functions/Show-TrayIcons.ps1



function Show-TrayIcons {
    [CmdletBinding()]
    param (
        [Parameter()] [switch] $Hide
    )

    $regLocation = "HKCU:\Control Panel\NotifyIconSettings\"

    if (Test-Path $regLocation) {
        $TrayIcons = Get-ChildItem $regLocation

        # $TrayIcons

        foreach ($t in $TrayIcons) {

            Write-Verbose $t.Name
            # $IsPromoted = Get-ItemProperty "registry::$($t)" -Name IsPromoted | Select-Object -ExpandProperty IsPromoted

            if ($Hide) {
                $value = 0
            } else {
                $value = 1
            }
            if ((Get-ItemProperty "registry::$($t)" -Name ExecutablePath) -match "OneDrive.exe") {
                New-ItemProperty "registry::$($t)" -Name IsPromoted -Value 1 -Force | Out-Null
            } else {
                New-ItemProperty "registry::$($t)" -Name IsPromoted -Value $value -Force | Out-Null
            }

        }
    } else {
        Write-Warning "Reg key `"$($regLocation)`" not found"
    }



}