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.
Technology Tips and News
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.
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
This is the code.
Get-ChildItem "$env:USERPROFILE\Desktop\*.lnk" |ForEach-Object { Remove-Item $_ }
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
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.
... or direct. Get-ChildItem is not necessary in this situation.Remove-Item -Recurse "$env:USERPROFILE\Desktop\*.lnk"
... or direct. Get-ChildItem is not necessary in this situation.Remove-Item -Recurse "$env:USERPROFILE\Desktop\*.lnk"
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
... or direct. Get-ChildItem is not necessary in this situation.Remove-Item -Recurse "$env:USERPROFILE\Desktop\*.lnk"