Forum Discussion
deleting a shortcut on desktop via intune
- 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
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 ?
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- 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 - AB21805Mar 15, 2022Bronze Contributor
Same issue again hasnt run. I have checked the agent extractor and I noticed this:
What can I try to fix this?
- AB21805Mar 15, 2022Bronze Contributoryes they are! I will let you know how I get on with this! Thanks again!
- 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 Contributor
All set up
Are the config correct like 64 bit powershell?
- Mar 15, 2022Ok.. Just put in a Notepad and copy/paste from there perhaps?
- AB21805Mar 15, 2022Bronze Contributorso 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 be like it is in my post, I think copy/paste destroyed the formatting in the first line
- AB21805Mar 15, 2022Bronze Contributor
Does this look correct?
Dont know whats at the beginning of each script with those random symbols as I didnt include that when putting scripts in powershell