IT Consultant Everyday Notes

Just some problems/solutions storage

Intune: Remove Microsoft Teams shortcut

I am in the middle of Windows Autopilot project. The Customer wants Microsoft Teams be a part of an Application set we install.

We are also implementing One Drive Known folder Move  (KFM) to redirect desktop to One Drive for Business.

The problem is related to Teams behaviour – it installs its shortcut on a user desktop every time it is installed. As a result we do have multiple Teams shortcuts after each device wipe – Teams creates a shortcut and after that another shortcut is synchronized by KFM from One Drive.

I spent a while, trying to find a solution to disable Teams shortcut creation; but it looks like at that time Microsoft does not provide any policy/registry settings to prohibit that.

So, I decided to delete the excessive shortcut using PowerShell script.   The problem with that is Intune behaviour – it runs a script only once Smile. From my experience KFM kicks on quite a while after the user logon, so PowerShell script being added to the process will just miss it.

After all I decided to create a Win32 application in Intune and set up a detection rule to be sure the App will run (and re-run) when it is required.

Here is the removeshortcut.ps1 script to delete the excessive shortcuts

$DesktopPath = [Environment]::GetFolderPath(“Desktop”)
remove-item -path $DesktopPath\* -filter “Microsoft Teams (*.lnk”

Here is install.cmd acting as “Install” in win32 app

powershell.exe -ExecutionPolicy Bypass -command “& ‘.\removeshortcut.ps1′”

Here is detection.ps1 script for win32 application

$DesktopPath = [Environment]::GetFolderPath(“Desktop”)
if (-Not (Test-Path -Path “$desktoppath\Microsoft Teams (*.lnk”)) {write-host “missing”}

After that I packaged the “application” using IntuneWinAppUtil.exe tool and created a Win32 Application in Intune (it must be run in User context) and assigned it to a group of Users.

On the first run it successfully removed the shortcuts. I put them back to see when Intune realizes the “application” is not installed and run the command again Smile . Unfortunately, according MS dock re-evaluation will happen in 24 hours… Sad smile   https://docs.microsoft.com/en-us/intune/apps-add

7 responses to “Intune: Remove Microsoft Teams shortcut

  1. jeff October 1, 2019 at 7:10 am

    doesn’t seems to work for me. anyone else tried and is working?

    when i manually ran the code, the microsoft teams.lnk does not delete.
    $DesktopPath = [Environment]::GetFolderPath(“Desktop”)
    remove-item -path $DesktopPath\* -filter “Microsoft Teams (*.lnk”

    • alex416 October 1, 2019 at 10:36 am

      I am deleting copies (their names contains (2), (3) etc… suffixes), not the original link. If you wish to delete all links you can tweak the filter and use “Microsoft Teams*.lnk” instead of the one I used.

  2. Alex March 1, 2020 at 8:26 pm

    I love the idea but suck with powershell. Maybe you can help me troubleshoot why its not working for me. Not sure why but when I copied the code originally it created some odd characters in the text and I was finally able to figure it out.

    Now I am stuck with an error when I try to run install.cmd
    At C:\Teams\removeshortcut.ps1:1 char:54
    + $DesktopPath = [Environment]::GetFolderPath(“Desktop”)
    + ~
    Missing ‘)’ in method call.
    At C:\Teams\removeshortcut.ps1:1 char:54
    + $DesktopPath = [Environment]::GetFolderPath(“Desktop”)
    + ~
    Unexpected token ‘’ in expression or statement.
    At C:\Teams\removeshortcut.ps1:1 char:55
    + $DesktopPath = [Environment]::GetFolderPath(“Desktop”)
    + ~
    Unexpected token ‘)’ in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

    any idea what I might be missing here? Adding parenthesis like it said in the error ID did not seem to help

  3. michaelvds September 11, 2020 at 5:10 am

    This is exactly what I was looking for thanks a lot!!!

    • michaelvds September 11, 2020 at 9:26 am

      Just an extra question. What did you use as Uninstall command ?
      Do

      • alex416 February 28, 2021 at 7:08 pm

        I did not configure uninstall command since did not have a purpose to install the shortcut back. Thinking about the approach now I would probably configure both install and uninstall parts and deploy Uninstall part (which would be the same script as now, while install part would copy shortcut (but never used)).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: