Public/New-ShortcutFile.ps1

function New-ShortcutFile
{
    <#
    .DESCRIPTION
        Create a new shortcut with an existing icon file

    .EXAMPLE
        New-ShortcutFile -IconFolder "$ENV:ALLUSERSPROFILE\MyFolder\" -IconName "icon.ico" -ShortcutPath "$ENV:ALLUSERSPROFILE\Microsoft\Windows\Start Menu\Programs\MyShortcut.lnk" -TargetPath "https://myurl.com"

    .NOTES
        Created by: Jon Anderson
        Modified: 2023-07-03
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
        [String]$IconFolder,
        [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
        [String]$IconName,
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()]
        [String]$ShortcutPath,
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()]
        [String]$TargetPath
    )
    
    Write-LogEntry -Value "Creating a new shortcut file with the following parameters`n$($ShortcutPath)`n$($TargetPath)`n$($IconFolder)`n$($IconName)" -Severity 1
    $IconPath = $IconFolder + $IconName
    if(!(Test-Path -Path $IconFolder))
    {
        New-Item -Path $IconFolder -ItemType Directory -Force
    }
    if(!(Test-Path -Path "$IconFolder\$IconName"))
    {
        Copy-Item -Path "$PSScriptRoot\$IconName" -Destination $IconPath
    }
    $null = $WshShell = New-Object -comObject WScript.Shell
    $IconFile = "IconFile=" + $IconPath
    $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
    $Shortcut.TargetPath = $TargetPath
    $Shortcut.Save()
    Add-Content $ShortcutPath "HotKey=0"
    Add-Content $ShortcutPath "$IconFile"
    Add-Content $ShortcutPath "IconIndex=0"
}