Public/Remove-specStartMenuShortcut.ps1

function Remove-specStartMenuShortcut {
    <#
    .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-specStartMenuShortcut -ShortcutName "MyApp" -AllUsers
        Deletes the Start Menu shortcut named "MyApp" for all users.
 
    .EXAMPLE
        $shortcutParams = [pscustomobject]@{
        ShortcutName = 'Tonoref'
        AllUsers = $true
    }
 
    $shortcutparams | Remove-specStartMenuShortcut
 
    Using pipeline to delete a shortcut from All Users Start Menu
 
 
    .NOTES
        File: Remove-specStartMenuShortcut.ps1
        Author: owen.heaume
        1.0 - Initial function creation
    #>

    [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 "Delete start menu shortcut: successfully removed shortcut: $shortcutPath" -ForegroundColor DarkGreen
                } catch {
                    Write-Warning $_.Exception.Message
                }
            } else {
                Write-Host "Delete start menu shortcut: Shortcut does not exist: $shortcutPath" -ForegroundColor DarkYellow
            }
        }
    }
}