How to deploy custom URL shortcuts with Microsoft Intune

This article will describe how to deploy custom URL shortcuts with Microsoft Intune.

05/10/2022 UPDATE: added some adjustments to the script and also added the possibility to add a custom icon.

Welcome to my first post in my “Cases from the Field” series. This series will describe things I’ve done during the projects I’ve worked on as a Modern Workplace Consultant.


Let me briefly describe what our customer requested. They use 2 web applications and want them as a URL shortcut on their Windows 10/11 enrolled device. Instead of doing this manually for all their devices, they asked if it is possible to do this with Microsoft Intune.

To make this possible I’ve deployed a Powershell script with Microsoft Intune. The script (updated version with custom icon) is very simple:

#Variables creating local folder and download .ico file
$LocalIconFolderPath = "C:\URLIcon"
$SourceIcon = "http://nickydewestelinck.be/wp-content/icons/salesforce.ico"
$DestinationIcon = "C:\URLIcon\salesforce.ico"


#Step 1 - Create a folder to place the URL icon
New-Item $LocalIconFolderPath -Type Directory

#Step 2 - Download a ICO file from a website into previous created folder
curl $SourceIcon -o $DestinationIcon

#Step 3 - Add the custom URL shortcut to your Desktop with custom icon
$new_object = New-Object -ComObject WScript.Shell
$destination = $new_object.SpecialFolders.Item('AllUsersDesktop')
$source_path = Join-Path -Path $destination -ChildPath '\\Salesforce.lnk'
$source = $new_object.CreateShortcut($source_path)
$source.TargetPath = 'https://login.salesforce.com'
$source.IconLocation = ”C:\URLIcon\salesforce.ico”
$source.Save()

This Powershell script creates a custom URL shortcut with custom icon and places it in the Public Desktop folder of your Windows 10/11 device. In this case, it will place a URL shortcut “Salesforce” and this will go to https://login.salesforce.com/

How to deploy custom URL shortcut with Microsoft Intune

Now let me show you how to deploy this Powershell Script with Microsoft Intune.

Step 1: Create a Powershell Script (Updated)

This part of the article is an updated version. I’ve added a three extra steps, the first one or some variables we need to download and add an icon into a newly created folder locally. Be sure that your icon file is a .ico extension, I use X-Icon Editor (xiconeditor.com) to create/convert my image into a, .ico file and then upload them to my site. You can also use Azure blob storage to store your icon files.

For example, these are the variables:

#Variables creating local folder and download .ico file
$LocalIconFolderPath = "C:\URLIcon"
$SourceIcon = "http://nickydewestelinck.be/wp-content/icons/salesforce.ico"
$DestinationIcon = "C:\URLIcon\salesforce.ico"

Step 1 will create a folder on your device, it will be located at C:\URLIcon\.

#Step 1 - Create a folder to place the URL icon
New-Item $LocalIconFolderPath -Type Directory

Step 2 will download the .ico file and create one locally in the previously created folder. We use cURL for this part, more information here on cURL.

#Step 2 - Download a ICO file from a website into previous created folder
curl $SourceIcon -o $DestinationIcon

The last part will create the URL shortcut, with the custom icon, to the Public Desktop folder on the device.

#Step 3 - Add the custom URL shortcut to your Desktop with custom icon
$new_object = New-Object -ComObject WScript.Shell
$destination = $new_object.SpecialFolders.Item('AllUsersDesktop')
$source_path = Join-Path -Path $destination -ChildPath '\\Salesforce.lnk'
$source = $new_object.CreateShortcut($source_path)
$source.TargetPath = 'https://login.salesforce.com'
$source.IconLocation = ”C:\URLIcon\salesforce.ico”
$source.Save()

Copy the code above and copy it into an editor like Powershell ISE or Visual Studio Code.

#Variables creating local folder and download .ico file
$LocalIconFolderPath = "C:\URLIcon"
$SourceIcon = "http://nickydewestelinck.be/wp-content/icons/salesforce.ico"
$DestinationIcon = "C:\URLIcon\salesforce.ico"


#Step 1 - Create a folder to place the URL icon
New-Item $LocalIconFolderPath -Type Directory

#Step 2 - Download a ICO file from a website into previous created folder
curl $SourceIcon -o $DestinationIcon

#Step 3 - Add the custom URL shortcut to your Desktop with custom icon
$new_object = New-Object -ComObject WScript.Shell
$destination = $new_object.SpecialFolders.Item('AllUsersDesktop')
$source_path = Join-Path -Path $destination -ChildPath '\\Salesforce.lnk'
$source = $new_object.CreateShortcut($source_path)
$source.TargetPath = 'https://login.salesforce.com'
$source.IconLocation = ”C:\URLIcon\salesforce.ico”
$source.Save()

Now save this PowerShell script to your local computer as a .ps1 file. I named it Create-Desktop-URL-Shortcuts.ps1.

Step 2: Deploy script with Microsoft Intune

Go to https://endpoint.microsoft.com and sign-in with a Global Administrator or Intune Administrator.

Go to Devices => Scripts. Then click on +Add and choose for Windows 10.

how-to-deploy-custom-url-shortcuts-with-microsoft-intune

Give the Script a name. In this example it will be NDW – Add Custom URL shortcut to Desktop and click Next.

how-to-deploy-custom-url-shortcuts-with-microsoft-intune

Choose the PowerShell script created and saved in Step 1. Leave the extra settings as default.

how-to-deploy-custom-url-shortcuts-with-microsoft-intune

Assign it to All Devices or a group to those who need the deployment and click Next.

how-to-deploy-custom-url-shortcuts-with-microsoft-intune

Review your settings and click Add. Your script will now be added.

how-to-deploy-custom-url-shortcuts-with-microsoft-intune

Your script is now added and ready to deploy to the requested devices.

So this is how to deploy custom URL shortcuts with Microsoft Intune. Isn’t that difficult is it?

So this was the first post in my “Cases from the Field” series. Stay tuned for more…

Nicky De Westelinck

Nicky De Westelinck is a Modern Workplace Expert for Arxus with several years of experience in Microsoft 365. His main focus is Microsoft Intune and Microsoft 365 Administration. He is also a Microsoft Certified Trainer since 2021.

View all posts by Nicky De Westelinck →

64 thoughts on “How to deploy custom URL shortcuts with Microsoft Intune

      1. Hi. I too want to add a custom logo, but get this error after trying to add the additional line:

        Exception setting “IconLocation”: “The property ‘IconLocation’ cannot be found on this object. Verify that the property exists and can be set.

        Can you or any of your readers please suggest a fix?

          1. Didn’t work. I did this by example on powershell.

            $source.IconLocation= ”https://www.voys.nl/app/themes/voys/dist/images/logo.svg”

            Can you see the problem??

          2. Hi Levin,

            Apologies for the late reaction, but I was on Holiday. I tried it myself, but it seems that the URLs aren’t working.
            I going to try to make some time to check out a solution by creating a W32 app. I’ll keep you posted.

          3. Hi Levin,

            I’ve updated the script, but be sure to convert your .svg file to a .ico file. I used this this site => https://www.xiconeditor.com/.
            And instead of using the .URL in the link, you should change it to .lnk. That’s why the IconLocation property doesn’t work.

            I added some extra lines to the script. Steps are explained in the title. I’ve tested it in Sandbox and it worked.

            #Step 1 – Create a folder to place the URL icon
            New-Item “C:\URLIcon” -Type Directory

            #Step 2 – Download a ICO file from a website into previous created folder
            curl “http://nickydewestelinck.be/wp-content/icons/favicon.ico” -o C:\URLIcon\salesforce.ico

            #Step 3 – Add the custom URL shortcut to your Desktop with custom icon
            $new_object = New-Object -ComObject WScript.Shell
            $destination = $new_object.SpecialFolders.Item(‘Desktop’)
            $source_path = Join-Path -Path $destination -ChildPath ‘\\Salesforce.lnk’
            $source = $new_object.CreateShortcut($source_path)
            $source.TargetPath = ‘http://login.salesforce.com’
            $source.IconLocation = ”C:\URLIcon\salesforce.ico”
            $source.Save()

            Regards,
            Nicky

          4. Thanks for your info. If i deploy my script in Intune it doesn’t work. The script created a directory with the icon but the shortcut self isn’t visible. They only thing what is maybe the problem is that or organization policy blocked it. I think that is not the problem because without the icon the script works totally. Any idea what is happening??

  1. +My company has Android and Apple devices in Intune. I’ve been tasked with pushing a company website shortcut to all the Apple devices. I tried the script and it immediately says the uploaded file isn’t a valid script. Is there a wayto do this for iOs devices in Intune?

  2. Hi, thanks for the post. is there a universal repository of icons url hosted online that can be used to replace the internet explorer logo? If you know of any kindly point

  3. script is working fine but it is opening in Edge browser, Please suggest, how I can set it as Chrome instead of Edge.

  4. I would love to use this for creating shortcuts but, when I try to run the script in step 1 in an elevated Powershell window I just get the following error:-

    Unable to save shortcut “C:\Users\Public\Desktop\Salesforce.url”.
    At line:7 char:1
    + $source.Save()
    + ~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    Any ideas on how to resolve this?

    Many thanks in advance.

    1. Hi Mike,
      Apologies for my late response, I was on vacation for two weeks. 🙂
      I just tried the script and (for some odd reason) I received the same error. I managed to get it working by changing the $destination variable to “Desktop” instead of “AllUsersDesktop”.
      This worked for me, here is the “new script”.

      $new_object = New-Object -ComObject WScript.Shell
      $destination = $new_object.SpecialFolders.Item(“Desktop”)
      $source_path = Join-Path -Path $destination -ChildPath “\\Salesforce.url”
      $source = $new_object.CreateShortcut($source_path)
      $source.TargetPath = “http://login.salesforce.com”
      $source.Save()

      Greetings,
      Nicky

    1. Hi,

      Yes you can. Just copy these commands multiple times in the same script and change the path. For example:

      # Add Salesforce Shortcut
      $new_object = New-Object -ComObject WScript.Shell
      $destination = $new_object.SpecialFolders.Item(“Desktop”)
      $source_path = Join-Path -Path $destination -ChildPath “\\Salesforce.url”
      $source = $new_object.CreateShortcut($source_path)
      $source.TargetPath = “http://login.salesforce.com”
      $source.Save()

      #Add Google shortcut
      $new_object = New-Object -ComObject WScript.Shell
      $destination = $new_object.SpecialFolders.Item(“Desktop”)
      $source_path = Join-Path -Path $destination -ChildPath “\\Google.url”
      $source = $new_object.CreateShortcut($source_path)
      $source.TargetPath = “http://www.google.com”
      $source.Save()

      Greetings,
      Nicky

  5. Hi Nicky,

    Thanks for the script! Is there a line of code or a way to ensure that if an existing shortcut with the same name, i.e. salesforce.url is already present, to overwrite this rather than creating an additional one?

  6. Hi Nicky,

    I’m able to run local with elevated privileges but this fails as per you script settings. I even select to run on 64bit host as this works on some scripts I’ve deployed via Intune.

    Any suggestions?

    Thank you!

    1. Hi,

      Can you try this script?
      $new_object = New-Object -ComObject WScript.Shell
      $destination = $new_object.SpecialFolders.Item(“Desktop”)
      $source_path = Join-Path -Path $destination -ChildPath “\\Salesforce.url”
      $source = $new_object.CreateShortcut($source_path)
      $source.TargetPath = “http://login.salesforce.com”
      $source.Save()

      Regards.

  7. Nicky,

    Great script and works like a champ, but I would like to ask about icon again. So I can add the icon file and the extra line to the script, but I would like a suggestion from you. Since the whole point is to push this from InTune, then, in theory, there is no on-prem servers for things like storage of .ico files. If you had no file/DC servers, where in Azure would you store the .ico file itself?

    Appreciate any recommendations,
    Brian

  8. Hi Nicky,

    First of all, thank you for the code, it was exactly what I was looking for and it works brilliantly. Now for the second part, on how to delete previously added links, by googling I found something like this:

    $Icon1 = “Salesforce.lnk”
    If ((Test-Path “$env:AllUsers\Desktop\$Icon1”) -eq $true)
    {
    Remove-Item “$($env:AllUsers)\Desktop\$Icon1” –Force
    }

    Would something like this work?

    Regards

    1. Hi Salvatore,

      Big thanks for your feedback, it’s much appreciated! 😉
      What I always do for testing such scripts is, open Windows Sandbox and run those scripts there.
      The first step is to run the script that creates the link (as written in the blog), then run your script (the one above) to see if the link is removed. If it’s the case, I think your script works perfectly and you can deploy it. 😉

      Regards!

  9. Hi,

    My script is a bit different, but it does the same thing. When i manually execute it on the desktop , it works perfectly fine, but in the deployment with intune autopilot, it break because it try to put the shortcut in this :
    “C:\WINDOWS\system32\config\systemprofile\Desktop\Google-Chrome.lnk”.

    I think that it try to put shortcut while being in a special profil for installing so he don’t find the right profil. Here is my script :

    $shell = New-Object -ComObject WScript.Shell
    $appName = “Google-Chrome”
    $appPath = “C:\Program Files\Google\Chrome\Application\chrome.exe”
    $iconPath = $appPath

    # Récupération du chemin du profil utilisateur
    $userProfile = $env:USERPROFILE
    $lg = “Desktop”
    $shortcutPath = “$userProfile\$lg\$appName.lnk”
    $shortcut = $shell.CreateShortcut($shortcutPath)
    $shortcut.TargetPath = $appPath
    $shortcut.IconLocation = $iconPath
    $shortcut.Save()

    $appName = “Wordd”
    $appPath = “C:\Program Files\Microsoft Office\root\Office16\WINWORD.exe”
    $iconPath = $appPath

    # Récupération du chemin du profil utilisateur
    $userProfile = $env:USERPROFILE
    $shortcutPath = “$userProfile\$lg\$appName.lnk”
    $shortcut = $shell.CreateShortcut($shortcutPath)
    $shortcut.TargetPath = $appPath
    $shortcut.IconLocation = $iconPath
    $shortcut.Save()

    # RAJOUTER \OneDrive\ ENTRE USERPROFILE ET LG SI L’UTILISATEUR VA UTILISER ONEDRIVE

  10. Hi There,

    I have managed to deploy a shortcut to my desktop following your guide. It also has a custom Icon which is great. Intune has pushed this out perfectly.

    however, when double clicking the shortcut on my desktop it comes up with “Missing Shortcut”? Have I done something wrong? This is the code I have used! Any help will be much appreciated.

    I also have a URLIcon on my C Drive containing the .ico file.

    “FYI Line 3 SourceIcon I have removed the blob storage URL for security reasons on this feed. But rest assured its in there when deploying the script!”

    #Variables creating local folder and download .ico file
    $LocalIconFolderPath = “C:\URLIcon”
    $SourceIcon = “Removed”
    $DestinationIcon = “C:\URLIcon\Ulysses Incident Reporting.ico”

    #Step 1 – Create a folder to place the URL icon
    New-Item $LocalIconFolderPath -Type Directory

    #Step 2 – Download a ICO file from a website into previous created folder
    curl $SourceIcon -o $DestinationIcon

    #Step 3 – Add the custom URL shortcut to your Desktop with custom icon
    $new_object = New-Object -ComObject WScript.Shell
    $destination = $new_object.SpecialFolders.Item(‘AllUsersDesktop’)
    $source_path = Join-Path -Path $destination -ChildPath ‘\\Ulysses Incident Reporting.lnk’
    $source = $new_object.CreateShortcut($source_path)
    $source.TargetPath = ‘ulysses.everyturn.org’
    $source.IconLocation = ”C:\URLIcon\Ulysses Incident Reporting.ico”
    $source.Save()

  11. Hi Guys, sorry never mind I have got it working! I didnt put in the https:// at the front of my URL

    This is now resolved. Thanks for your help!!

  12. Great read and easy-to-follow guide!

    Noob question: how often do scripts placed here, run? Every single logon? And if so, does it overwrite this shortcut everytime?

    1. Hi Gman,

      The Intune Management client will check at logon and only run again if there are changes in the script and will overwrite the current configuration. If there are no changes, it will do nothing.

  13. Love the script, makes things so much easier. Unfortunately, its not deploying the shortcut with the .ico. I see that it downloaded the file in question but is not being used as the icon for the shortcut. Thoughts?

    1. Hi James, if you run the script manually on your device does it work? Is the location to the icon correct in the script, it should point to the local UNC path where the .ico file is copied/located ($DestinationIcon = “C:\“)
      I’ve also noticed (during my test) that the .ico file can be corrupted or bad so it wouldn’t show either, did you use to tool mentioned in the post?
      If you want, you can always send your script and I’ll check it out.

      Kind regards,
      Nicky

  14. Hi all,

    Here’s an alternative when trying to create the directory in step 1.
    With this piece you can check if the directory already exists and skip creating it.
    It prevents the script from throwing an error.
    In this way you can use the script again using the same directory name.

    #Step 1 – Create directory if doesn’t exist
    if (-not (Test-Path -LiteralPath $LocalIconFolderPath)) {

    try {
    New-Item -Path $LocalIconFolderPath -ItemType Directory -ErrorAction Stop | Out-Null #-Force
    }
    catch {
    Write-Error -Message “Unable to create directory ‘$LocalIconFolderPath’. Error was: $_” -ErrorAction Stop
    }
    “Successfully created directory ‘$LocalIconFolderPath’.”

    }
    else {
    “Directory already exists”
    }

  15. Hello,
    I followed the instructions, but when deploying the script into Intune, the script fails. When I run the script on my local computer it doesn’t fail. Below is my script for reference.

    New-Item “C:\URLIcon” -Type Directory
    $new_object = New-Object -ComObject WScript.Shell
    $destination = $new_object.SpecialFolders.Item(“Desktop”)
    $source_path = Join-Path -Path $destination -ChildPath “\\STAT Microsoft 365.lnk”
    $source = $new_object.CreateShortcut($source_path)
    $source.TargetPath = “https://login.microsoftonline.com/”
    $source.IconLocation = ”C:\URLIcon\stat.ico”
    $source.Save()

    $new_object = New-Object -ComObject WScript.Shell
    $destination = $new_object.SpecialFolders.Item(“Desktop”)
    $source_path = Join-Path -Path $destination -ChildPath “\\LogMeIn.lnk”
    $source = $new_object.CreateShortcut($source_path)
    $source.TargetPath = “https://accounts.logme.in/login.aspx”
    $source.IconLocation = ”C:\URLIcon\logmein.ico”
    $source.Save()

    $new_object = New-Object -ComObject WScript.Shell
    $destination = $new_object.SpecialFolders.Item(“Desktop”)
    $source_path = Join-Path -Path $destination -ChildPath “\\Paylocity.lnk”
    $source = $new_object.CreateShortcut($source_path)
    $source.TargetPath = “https://access.paylocity.com/”
    $source.IconLocation = ”C:\URLIcon\paylocity.ico”
    $source.Save()

  16. Hi Nicky,
    Thank you for the script!
    Trying to deploy it via the Win32 Intune app, it’s asking for the “uninstall” command. What would I provide if I wanted to remote the shortcut altogether using a separate script?
    Thanks again.

  17. Hi Nicky,
    Many thanks, Apperciate your efforts.
    I tried the script. it is creating the shortcut, crerating the folder, downloading the ico file but the shortcut is taking the icon.
    any thoughts?

  18. Hi Nicky,
    Many thanks, Apperciate your efforts.
    I tried the script. it is creating the shortcut, crerating the folder, downloading the ico file but the shortcut is not taking the icon.
    any thoughts?

  19. I ran the script on my personal computer and its working like a charm. you think its failing due to permission issues from intune?

    Kind Regards,

  20. Hi Nicky, I figured that icon change need admin privileges. Is there a way to incorporate this within the script?

    Kind Regards,

  21. Hello! The following script works for me, but there seem to be a few issues.

    Script:

    $LocalIconFolderPath = “C:\URLIcon”
    $SourceIcon = “URL TO IMAGE HERE”
    $DestinationIcon = “C:\URLIcon\IT Support.ico”

    New-Item $LocalIconFolderPath -Type Directory

    curl $SourceIcon -o $DestinationIcon

    $new_object = New-Object -ComObject WScript.Shell
    $destination = $new_object.SpecialFolders.Item(‘AllUsersDesktop’)
    $source_path = Join-Path -Path $destination -ChildPath ‘\\IT Help Desk.lnk’
    $source = $new_object.CreateShortcut($source_path)
    $source.TargetPath = ‘https://silveredge.service-now.com/esc?id=sc_cat_item&sys_id=4416f6b087e39190d8d821f9cebb35b7’
    $source.IconLocation = ”C:\URLIcon\IT Support.ico”
    $source.Save()

    – Where URL IMAGE HERE i place the URL of the .ico file from our SharePoint page.
    – When I run the script, the folder is created in the C drive and the .ico file is placed there. The desktop icon is also created.
    – However, the .ico file that is placed in the C drive is just a white piece of paper and that transfers over to the desktop as well. So, the icon i have created does not properly appear.

    Do you know how I could get this to appear properly?

    1. Hi Aubrey,

      I’ve also noticed (during my test) that the .ico file can be corrupted or bad so it wouldn’t show either, did you use to tool mentioned in the post?
      Also, I’m not a fan on using a file on SharePoint.

      Kind Regards,
      Nicky

Leave a Reply

Your email address will not be published. Required fields are marked *