Forum Discussion
AB21805
Mar 14, 2022Bronze Contributor
deleting a shortcut on desktop via intune
Hi all, How do I delete a shortcut via intune? I have created a shortcut using powershell but I had to update the URL which seems to have broke the shortcut so need to delete it and redeploy...
- Mar 15, 2022
AB21805 Changed it to handle both situations:
Detection:
$desktop = [Environment]::GetFolderPath("Desktop") if (Test-Path -Path "$($desktop)\Wifi Connect.lnk") { write-Host Found shortcut exit 1 } Else { Write-Host Shortcut not found exit 0 }
Remediation:
$desktop = [Environment]::GetFolderPath("Desktop") Remove-Item -Path "$($desktop)\Wifi Connect.lnk" -Force:$true
Scripts in Devices should also work, if you know the filename and it only has to run once.. ("remove-item c:\users\public\desktop\shortcut.url")
AB21805
Mar 15, 2022Bronze Contributor
Hi
This doesnt work for me, the shortcuts are in C:\users\theuser\Desktop
Is there a way I can create a script to delete it via the user logged in's desktop?
This doesnt work for me, the shortcuts are in C:\users\theuser\Desktop
Is there a way I can create a script to delete it via the user logged in's desktop?
- Mar 15, 2022It should be like it is in my post, I think copy/paste destroyed the formatting in the first line
- Mar 15, 2022Ok.. Just put in a Notepad and copy/paste from there perhaps?
- Mar 15, 2022I don't think it really matters in this case what version you use, you're client are all 64bit I guess 😉
- AB21805Mar 15, 2022Bronze Contributoryes they are! I will let you know how I get on with this! Thanks again!
- Mar 15, 2022
Two things 🙂
1- Use Remove-Item "$($env:USERPROFILE)\desktop\Wifi Connect.lnk" -force:$true because there's space in the filename
2- You're not running it as the logged in user in the Remediation screenshot that your shared - Mar 15, 2022And also for the detection 😛 (Change the path)
- Mar 15, 2022But do you redirect the desktop/my documents/my pictures to OneDrive? Because then the path would be different
- Mar 15, 2022Scripts work as system, so that's not going to work indeed. So, Remediation is an option but you have issues doing that somehow now... You could also create a Win32 package and run that as user to delete the file but.. Detection is done as system there, you could create a file in c:\programdata\company\shortcutdelete\shortcut.txt somehting and check on that. If not there, run the install.cmd from the Win32 package which deletes the file from the desktop and creates the shortcut.txt file so that is does not run again..
But.. You're main question was: "I have created a shortcut using powershell but I had to update the URL which seems to have broke the shortcut so need to delete it and redeploy a new shortcut. " You could create a new package which deletes the old shortcut/replaces the shortcut and does a detection on a file like I mentioned before? - AB21805Mar 15, 2022Bronze ContributorHow would I do this? either option would be fine I just really need to get this shortcut off as the link doesnt seem to be replaced with the correct one.
I used this site/script to create the shortcut: https://www.thelazyadministrator.com/2019/11/14/deploy-web-link-shortcuts-to-the-desktop-and-start-menu-using-intune/
So im guessing the win package would point to a script? What would the script contain? to delete from users desktop? Would I create a detection file with the win32 app or after so that the shortcuts deleted first ? - Mar 15, 2022
AB21805 Remediation script would be better, it's more difficult running a uninstall and detection for user things...
Detection script
if (Test-Path -Path $env:USERPROFILE\Desktop\shortcut.lnk) { write-Host Found shortcut exit 1 } Else { Write-Host Shortcut not found exit 0 }
Remediation script:
Remove-Item $env:USERPROFILE\Desktop\shortcut.lnk -Force:$true