Skip to content

Instantly share code, notes, and snippets.

@Szeraax
Last active March 5, 2023 05:36
Show Gist options
  • Save Szeraax/f15acaa714009ba146770ad6b4895fe8 to your computer and use it in GitHub Desktop.
Save Szeraax/f15acaa714009ba146770ad6b4895fe8 to your computer and use it in GitHub Desktop.
A script that you can extend to get shortcuts back!
#!ps
$links = [ordered]@{
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
"C:\Program Files\Microsoft\Edge\Application\msedge.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
"C:\Program Files\Google\Chrome\Application\chrome.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk"
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk"
"C:\Program Files\Microsoft Office\root\Office16\EXCEL.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Excel.lnk"
"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook.lnk"
"C:\Program Files\Microsoft Office\root\Office16\WINWORD.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word.lnk"
"C:\Program Files\Microsoft Office\root\Office16\MSACCESS.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Access.lnk"
"C:\Program Files\Microsoft Office\root\Office16\POWERPNT.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerPoint.lnk"
"C:\Program Files\Microsoft Office\root\Office16\MSPUB.exe" =
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Publisher.lnk"
}
$links.GetEnumerator() | ForEach-Object {
$TargetFile = $_.Name
$ShortcutFile = $_.Value
if ((Test-Path $TargetFile) -and -not (Test-Path $ShortcutFile)) {
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
"Saved $ShortcutFile"
if ($ShortcutFile -notmatch "Chrome|Edge" -and $TargetFile -notmatch "Microsoft Office" ) {
"Copying to user programs now!"
Get-ChildItem C:\users | Where-Object { Test-Path "$($_.FullName)\appdata" } | ForEach-Object {
$_.Name
Copy-Item $ShortcutFile ($ShortcutFile -replace "C:\\ProgramData\\","$($_.FullName)\AppData\Roaming\")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment