# PowerShell code
# Create an icon on all users' desktop
# Author : RC 2021-07-07
# Initial values
$Shortcut_Path = "C:\Users\Public\Desktop\shortcut.URL" # where does the shortcut go
$Target_Path = "https://google.com" # what is the URL for this shortcut
$Icon_filename = "test.ico" # What icon file, in current (cache) folder
# If previous shortcut is there, delete it
Get-ChildItem $Shortcut_Path -ErrorAction SilentlyContinue |
Remove-Item -ErrorAction SilentlyContinue
# Create the shortcut (with generic icon)
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($Shortcut_Path)
$shortcut.TargetPath = $Target_Path
$shortcut.Save()
# copy icon file from current folder to \Windows folder
Copy-Item -Path $Icon_filename -Destination $ENV:WINDIR -ErrorAction SilentlyContinue
# set the icon for the shortcut
Add-Content $Shortcut_Path "IconFile=$ENV:WINDIR\$Icon_filename"
Add-Content $Shortcut_Path "IconIndex=0"