Remove shortcut file

I need to delete shortcuts from desktop. any guidance would be helpful.

i have a sample script which is deleting shortcut, but not from inside folders.

July 8th, 2015 2:19am

Fine - and were is the script to be discussed?
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 2:25am

a shortcut is simply a file, so:

Get-ChildItem -Recurse C:\Users\username\Desktop | where {$_.Name -eq "test.lnk"} | Remove-Item -Confirm:$false

replace the username with yours and "test.lnk" with your shortcut name.

if you want all shrtcut, do this:

Get-ChildItem -Recurse C:\Users\username\Desktop | where {$_.Name -ilike "*.lnk"} | Remove-Item -Confirm:$false

July 8th, 2015 2:27am

This is the code.

Get-ChildItem "$env:USERPROFILE\Desktop\*.lnk" |ForEach-Object { Remove-Item $_ }

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 2:29am

a shortcut is simply a file, so:

Get-ChildItem -Recurse C:\Users\username\Desktop | where {$_.Name -eq "test.lnk"} | Remove-Item -Confirm:$false

replace the username with yours and "test.lnk" with your shortcut name.

if you want all shrtcut, do this:

Get-ChildItem -Recurse C:\Users\username\Desktop | where {$_.Name -ilike "*.lnk"} | Remove-Item -Confirm:$false

July 8th, 2015 2:30am

To make benny's answer more precise and simple.

Get-ChildItem "$env:USERPROFILE\Desktop\*.lnk" -recurse|ForEach-Object { Remove-Item $_ }

This code will fetch the items with .lnk extension from the desktop location (even inside multiple folders) and remove it.

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 2:34am

Remove-Item -Recurse "$env:USERPROFILE\Desktop\*.lnk"

... or direct. Get-ChildItem is not necessary in this situation.

July 8th, 2015 2:43am

Remove-Item -Recurse "$env:USERPROFILE\Desktop\*.lnk"

... or direct. Get-ChildItem is not necessary in this situation.

Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 2:46am

a shortcut is simply a file, so:

Get-ChildItem -Recurse C:\Users\username\Desktop | where {$_.Name -eq "test.lnk"} | Remove-Item -Confirm:$false

replace the username with yours and "test.lnk" with your shortcut name.

if you want all shrtcut, do this:

Get-ChildItem -Recurse C:\Users\username\Desktop | where {$_.Name -ilike "*.lnk"} | Remove-Item -Confirm:$false

July 8th, 2015 6:25am

Remove-Item -Recurse "$env:USERPROFILE\Desktop\*.lnk"

... or direct. Get-ChildItem is not necessary in this situation.

  • Edited by Guy Jascht Wednesday, July 08, 2015 6:41 AM
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 6:41am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics