30 November, 2022

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 Consultant for Wortell Belgium with several years of experience in Microsoft 365. His main focus is Microsoft EndPoint Manager and Microsoft 365 Administration. He is also a Microsoft Certified Trainer since 2021.

View all posts by Nicky De Westelinck →

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

  1. Any way to have this force use Internet Explorer? I have some legacy apps that only launch from IE.

      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??

  2. +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?

  3. 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

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

  5. 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

  6. 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?

  7. 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.

  8. 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

  9. 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!

Leave a Reply

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