How to Delete a Desktop Shortcut using Intune

You can easily deploy a desktop shortcut using Intune on any Windows 10 or Windows 11 device. However, if the deployed shortcut is broken and no longer working, you may want to delete that broken desktop shortcut.

Users may encounter difficulty deleting a desktop shortcut from C:\Users\Public\Desktop due to insufficient administrator rights. In such cases, IT admins can create a PowerShell script to remove the desktop shortcut and deploy this script using Intune.

You can delete Desktop Shortcut from any of the below locations:

  • Public Desktop location: C:\Users\Public\Desktop
  • User’s Profile Desktop location: C:\Users<username>\Desktop
  • Desktop Location when It’s redirected to OneDrive: C:\Users\<username>\OneDrive – myorg\Desktop.

Once you identify the location of the desktop shortcut, you can proceed with creating a PowerShell script and initiating an Intune deployment to deploy the script onto end-user devices for deleting the desktop shortcut.

Step 1 – Prepare the Powershell script

As an example, consider a desktop shortcut for the Zoom App that was deployed using Intune. Subsequently, the shortcut has become non-functional, and our objective is to delete it. After manually inspecting several devices, it has been identified that this broken shortcut is present on the Public Desktop location: C:\Users\Public\Desktop.

You can utilize the script provided below along with the given steps to delete the desktop shortcut of any application by updating the variable $ShortcutFile. Copy the script code and save it in a .ps1 file, for example, Zoom_delete_shortcut.ps1.

  • $ShortcutFile = Provide the location of the shortcut file which needs to be deleted.

Script to Delete a Desktop shortcut on C:\users\Public\Desktop Location

$ShortcutFile = "$env:Public\Desktop\Zoom.lnk"
if (Test-Path $ShortcutFile){
    Remove-Item $ShortcutFile
} else { Write-Output "Shortcut Not Found" }

If you do not want to delete a desktop shortcut from the Public desktop and prefer to remove it from the desktop within the user’s profile, you can use the following PowerShell script code. Save this code in a .ps1 file and use it for the deletion process.

The desktop path within the user’s profile is typically C:\Users<username>\Desktop. If your desktop has been redirected to OneDrive, then the user’s profile desktop location will be C:\Users<username>\OneDrive – myorg\Desktop. However, in the script code below, you only need to modify the $ShortcutFile variable, keeping the other lines of code as they are.

Script to Delete a Desktop shortcut from User Profile Location

$DesktopPath = [Environment]::GetFolderPath("Desktop")
$ShortcutFile = "$DesktopPath\Zoom.lnk"
if (Test-Path $ShortcutFile){
    Remove-Item $ShortcutFile
} else { Write-Output "Shortcut Not Found" }

Step 2 – Deploy the Powershell Script

Now that we have a PowerShell script file created in the previous step, we can deploy it on end-user devices using Microsoft Intune. Please follow the steps below to deploy the PowerShell script:

  • Log in to the Intune admin center.
  • Navigate to Devices > Scripts.
  • Click on + Add and choose Windows 10 and later.
Add the Powershell script to Intune
Add the Powershell script to Intune

Basics Tab

Provide a Name and Description of the Policy.

Script Settings

  • Script location – Select the Powershell script that you want to deploy.
  • Run this script using the logged on credentials – Change it to No
  • Enforce script signature check – Change it to No
  • Run script in 64 bit PowerShell Host – Change it to Yes
Delete desktop shortcut Powershell script Deployment using Intune
Delete desktop shortcut Powershell script Deployment using Intune

Assignments

Click on Add groups and add an Entra Security group containing windows devices.

Review + add

The final step is to review the information and click on Add to start the deployment process.

Sync Intune Policies

The device check-in process might not begin immediately. If you’re testing this policy on a test device, you can manually kickstart the Intune sync either from the device itself or remotely through the Intune admin center.

Alternatively, you can use PowerShell to force the Intune sync on Windows devices. Another way to trigger the Intune device check-in process is by restarting the device.

Step 3 – Monitor Deployment Progress

To verify the status of Powershell script Execution from the Intune admin center, follow the below steps:

  • Login on Microsoft Intune admin center.
  • Go to Devices > Scripts under the Policy section.
  • Click on the Script deployment and go to the Overview page to find the status.

End-user Experience

Powershell scripts are downloaded to the following location: C:\Program Files (x86)\Microsoft Intune Management Extension\Policies\Scripts. Once the execution of the PowerShell script is completed on the device, you will observe the disappearance of the targeted desktop shortcut icon from the C:\Users\Public\Desktop location.

If you have an additional requirement to create a new shortcut after deleting a broken one, you can refer to the blog post ‘How to create a desktop shortcut using Intune‘.

Zoom desktop shortcut deleted from Public Desktop using Powershell Script deployed using Intune
Zoom desktop shortcut deleted from Public Desktop using Powershell Script deployed using Intune

We can monitor the execution details of the script, including timestamps, and troubleshoot any issues by checking the Intune Management Extension log. The log file is located at C:\ProgramData\Microsoft\IntuneManagementExtension\Logs, and its name is IntuneManagementExtension.log.

IntuneManagementExtension.log file showing the deployed Powershell script code
IntuneManagementExtension.log file showing the deployed Powershell script code

Conclusion

In this blog post, we’ve discussed the process of deleting a desktop shortcut from end-user devices. There are two primary locations from which you can delete a desktop shortcut: the first is from C:\Users\Public\Desktop, and the second location is C:\Users<username>\Desktop or C:\Users<username>\OneDrive – myorg\Desktop.

The steps provided in this blog post are not limited to just deleting desktop shortcuts. You can customize the PowerShell script to target any file location and type. Deploying this modified script using Intune allows you to delete the specified targeted file across end-user devices.

For instance, if you wish to remove a file, such as C:\Temp\testfile.txt or D:\Human Resources\dailylog.xlsx, you can easily customize the PowerShell script to target these files. Once modified, deploy the script using Intune on end-user devices for efficient removal.

Leave a Comment

Discover more from TechPress

Subscribe now to keep reading and get access to the full archive.

Continue reading