Public/Remove-pseStartMenuShortcut.ps1

function Remove-pseStartMenuShortcut {
    <#
    .SYNOPSIS
        Deletes a Start Menu shortcut.
 
    .DESCRIPTION
        This function deletes a Start Menu shortcut based on the specified properties.
 
    .PARAMETER ShortcutName
        The name of the shortcut to be deleted (excluding the .lnk extension).
 
    .PARAMETER AllUsers
        Switch parameter. If present, the function will look for the shortcut in the All Users Start Menu.
 
    .EXAMPLE
        Remove-pseStartMenuShortcut -ShortcutName "MyApp" -AllUsers
        Deletes the Start Menu shortcut named "MyApp" for all users.
 
    .EXAMPLE
        $shortcutParams = [pscustomobject]@{
        ShortcutName = 'Tonoref'
        AllUsers = $true
    }
 
    $shortcutparams | Remove-pseStartMenuShortcut
 
    Using pipeline to delete a shortcut from All Users Start Menu
 
 
    .NOTES
        Author: owen.heaume
        Version: 1.0.0 - Initial release
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string[]]$ShortcutName,

        [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
        [switch]$AllUsers
    )

    begin {
    }

    Process {
        foreach ($name in $ShortcutName) {
            # Determine the Start Menu path
            if ($AllUsers.IsPresent) {
                $startMenuPath = [System.IO.Path]::Combine($env:ProgramData, 'Microsoft\Windows\Start Menu\Programs')
            } else {
                $startMenuPath = [System.IO.Path]::Combine($env:APPDATA, 'Microsoft\Windows\Start Menu\Programs')
            }

            $shortcutPath = Join-Path $startMenuPath "$name.lnk"

            if (Test-Path $shortcutPath) {
                try {
                    Remove-Item $shortcutPath -Force
                    Write-Host "Successfully removed shortcut: $shortcutPath" -ForegroundColor DarkGreen
                } catch {
                    Write-Error $_.Exception.Message
                }
            } else {
                Write-Host "$shortcutPath does not exist to delete" -ForegroundColor DarkYellow
            }
        }
    }
}