Public/New-ShortcutEncode.ps1

function New-ShortcutEncode
{
    <#
    .DESCRIPTION
        Create a new shortcut using an icon file encoded in base64

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

    .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=$true)][ValidateNotNullOrEmpty()]
        [String]$ShortcutPath,
        [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
        [String]$TargetPath,
        [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
        [String]$IconEncode
    )

    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
    }
    [byte[]]$Bytes = [convert]::FromBase64String($IconEncode)
    [System.IO.File]::WriteAllBytes($IconPath,$Bytes)
    $Shell = New-Object -ComObject WScript.Shell
    $Shortcut = $Shell.CreateShortcut($ShortcutPath)
    $Shortcut.TargetPath = $TargetPath
    $Shortcut.IconLocation = $IconPath
    $Shortcut.Save()
}