Skip to content

Instantly share code, notes, and snippets.

@LesFerch
Last active March 25, 2026 00:42
Show Gist options
  • Select an option

  • Save LesFerch/5665aa052bf267a7215aafee44b36b6c to your computer and use it in GitHub Desktop.

Select an option

Save LesFerch/5665aa052bf267a7215aafee44b36b6c to your computer and use it in GitHub Desktop.
Convert Internet Shortcuts (URL files) to Windows Shortcuts (LNK files)
param(
[Parameter(Mandatory = $true)]
[string]$FolderPath
)
if (-not (Test-Path $FolderPath -PathType Container)) {
Write-Error "Folder not found: $FolderPath"
exit 1
}
$wsh = New-Object -ComObject WScript.Shell
$explorer = "$env:WINDIR\explorer.exe"
Get-ChildItem -Path $FolderPath -Filter *.url -File -Recurse | ForEach-Object {
$urlFile = $_
$lines = Get-Content -LiteralPath $urlFile.FullName
$url = $null
$iconFile = $null
$iconIndex = 0
foreach ($line in $lines) {
if ($line -like "URL=*") {
$url = $line.Substring(4)
}
elseif ($line -like "IconFile=*") {
$iconFile = $line.Substring(9)
}
elseif ($line -like "IconIndex=*") {
$iconIndex = [int]$line.Substring(10)
}
}
if (-not $url) {
Write-Warning "No URL found in $($urlFile.FullName). Skipping."
return
}
$lnkPath = [System.IO.Path]::ChangeExtension($urlFile.FullName, ".lnk")
try {
$shortcut = $wsh.CreateShortcut($lnkPath)
$shortcut.TargetPath = $explorer
$shortcut.Arguments = '"' + $url + '"'
$shortcut.WorkingDirectory = Split-Path $explorer
if ($iconFile) {
$shortcut.IconLocation = "$iconFile,$iconIndex"
}
$shortcut.Save()
Write-Output "Created: $lnkPath"
}
catch {
Write-Warning "Failed: $($urlFile.FullName) -> $_"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment