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
It should be like it is in my post, I think copy/paste destroyed the formatting in the first line
AB21805
Mar 15, 2022Bronze Contributor
so strange today any code I make in powershell and upload to proactive analytics area in endpoint comes up with those random code ill try using visual studio
- Mar 15, 2022It should clear up the next time, it gives you the status 'with issues' because it detected a condition that you don't want (Shortcut exists) Remediation worked, issue fixed, and it should report 'Without issues' later on
- AB21805Mar 15, 2022Bronze Contributor
I am now confused aha
Issue fixed on remediation status but with issues on detection status
- 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
- AB21805Mar 15, 2022Bronze Contributorsome students have got this set up too.
I would think I need to put both in the script, is that possible - Mar 15, 2022But do you redirect the desktop/my documents/my pictures to OneDrive? Because then the path would be different
- Mar 15, 2022Yes, in case of spaces in file or directory you need to escape that. You can test it on your own machine by creating the wifi connect shortcut on your desktop. You did forget the closing )-sign , it should be like this:
if (Test-Path -Path "$($env:USERPROFILE)\desktop\Wifi Connect.lnk") {
write-Host Found shortcut
exit 1
}
Else {
Write-Host Shortcut not found
exit 0
} - AB21805Mar 15, 2022Bronze ContributorSo would that look like:
if (Test-Path -Path "$($env:USERPROFILE)\desktop\Wifi Connect.lnk" {
write-Host Found shortcut
exit 1
}
Else {
Write-Host Shortcut not found
exit 0
} - Mar 15, 2022And also for the detection 😛 (Change the path)
- AB21805Mar 15, 2022Bronze Contributor
- 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