Skip to main content

Deploying Teams Backgrounds to macOS Devices

· loading ·
Microsoft Intune macOS Microsoft Teams Apps Shell Script
Author
Nick Benton
Principal Cloud Endpoint Consultant | Intune Blogger
Table of Contents

What happens when a stranger on the Internet asks you to look at something they’ve got a problem with? Well clearly you jump at the chance and hope that it’s not a body part this time. So here we are, looking at how to deploy Microsoft Teams Backgrounds to macOS devices using Intune, for organisations without the licensing to allow for corporate branding using Microsoft Teams Premium Experience.

Teams Meeting Backgrounds
#

So after a quick search, to add new backgrounds for Teams we need to dump files in ~/Library/Application Support/Microsoft/Teams/Backgrounds, this directory will exist under the logged in User context, so we’re going to need a way to both create an ‘Uploads’ directory and dump the background files in there.

Checking for the Teams App
#

Before we start throwing files in a directory, we should probably check to see if Teams is actually installed, luckily having spent many evenings peering over the macOS Shell Scripts hosted in Intune Shell Scripts, we can use the Dock Customisation script, as there’s a section in there that waits for the detection of apps before allowing the script to continue.

So we’ll pinch that section and update it so it’s only checking for the Microsoft Teams.app

teamsapp="/Applications/Microsoft Teams.app"

while [[ $ready -ne 1 ]]; do
  missingappcount=0
  if [[ -a "$teamsapp" ]]; then
    echo "$(date) |  $teamsapp is installed"
  else
    let missingappcount=$missingappcount+1
  fi
  echo "$(date) |  [$missingappcount] application missing"

    if [[ $missingappcount -eq 0 ]]; then
    ready=1
    echo "$(date) |  Teams App found, lets prep the dock"
  else
    echo "$(date) |  Waiting for 10 seconds"
    sleep 10
  fi
done

This will sit and wait for Teams to be detected, so make sure you’ve either already deployed Teams to your devices and/or have a ‘Required’ install intent for either Microsoft Teams or Microsoft Office, in Intune.

Getting the Logged in User
#

Like the Dock Customisation script, we can run the script from Intune as the signed-in user, and as we’re dealing with data in the User context, this makes the most sense. We can capture the signed-in user using the built-in $HOME variable, and creating a new teamsUpload variable to use later.

teamsUpload="$HOME/Library/Application Support/Microsoft/Teams/Backgrounds/Uploads"

Checking the Background Directory
#

Right, that was easier than I thought, we should look at how to check if the directory exists, and if not create it.

if [[ -d ${teamsUpload} ]]
then
    echo "$(date) | Teams Background Upload dir [$teamsUpload] already exists"
else
    echo "$(date) | Creating [$teamsUpload]"
    mkdir -p "$teamsUpload"
fi

Now onto how we get files in the directory, without just copy and pasting.

You may have noticed by now that I’m not explaining in much depth how the Shell commands work, well that’s because I’m still on a steep learning curve myself. Bear with me here, it ain’t PowerShell is it.

Deploying Files with Shell Scripts
#

I already know there’s a working method to deploy a Desktop Background to a macOS device enrolled in Microsoft Intune. So we’ll do what any right minded Consultant would do, and steal modify the script to our needs.

Script Variables
#

The original script used a single variable wallpaperurl to capture the desktop wallpaper URL, which is nice and all, and obviously fits the Desktop Background purpose, but we’d like to give our users options of Teams Backgrounds, so we’ll use an array to hold our list of URLs to the background files (see I am learning).

backgroundurls=("https://memv.ennbee.uk/bgr.png" "https://memv.ennbee.uk/wp-lt.png" "https://memv.ennbee.uk/wp.png")

For any additional URLs, you can add a new line to the array.

This lack of a $ when configuring new variables is unsettling me if I’m honest, but we move.

Downloading with Curl
#

Pretty simple really, even I can use curl to download the background files to the directory location -L, passing in the URL and a filename as part of the output -o option. We’ve added the `-s’ so as to not clog the log file with the raw download data.

curl -s -L -o $teamsUpload/$backgroundfile $backgroundurl

We now need to loop through each of the items in the backgroundurls array, and we also need to give each a filename for backgroundfile that isn’t duplicated, otherwise we’ll end up downloading and overwriting the same file for each URL in the array.

Incremental Filenames
#

We can quickly create new file names as part of the for loop needed for the items in the array, by incrementing a variable, and appending that variable to the backgroundfile variable.

i=0
for backgroundurl in "${backgroundurls[@]}"; do
  ((i=i+1))
  backgroundfile="TeamsBackground$i.png"
...
done

This will make sure that each downloaded background file gets a new filename, this won’t cater for multiple initiations of the script, but remember, I’m still new at this.

Teams Background Script
#

The full script looks pretty much like the below, which is just a squishing together of the bits we’ve already covered in this post.

#!/bin/bash
#set -x

############################################################################################
##
## Script to download Teams Backgrounds
##
###########################################

# Define variables
# Add new background URLs to the array
backgroundurls=("https://raw.githubusercontent.com/ennnbeee/mem-scripts/main/Intune/Scripts/Shell/TeamsBackgrounds/Msft_Nostalgia_Landscape.jpg"
  "https://raw.githubusercontent.com/ennnbeee/mem-scripts/main/Intune/Scripts/Shell/TeamsBackgrounds/SupportUkraine_Heart_TeamsBackground.jpg"
  "https://raw.githubusercontent.com/ennnbeee/mem-scripts/main/Intune/Scripts/Shell/TeamsBackgrounds/covermichael.jpg")

scriptname="SetTeamsBackground"
teamsapp="/Applications/Microsoft Teams.app"
logandmetadir="$HOME/Library/Logs/Microsoft/Intune/Scripts/$scriptname"
log="$logandmetadir/$scriptname.log"
teamsUpload="$HOME/Library/Application Support/Microsoft/Teams/Backgrounds/Uploads"

## Check if the log directory has been created
if [ -d $logandmetadir ]; then
  ## Already created
  echo "# $(date) | Log directory already exists - $logandmetadir"
else
  ## Creating Metadirectory
  echo "# $(date) | creating log directory - $logandmetadir"
  mkdir -p "$logandmetadir"
fi

# start logging
exec 1>>"$log" 2>&1

echo ""
echo "##############################################################"
echo "# $(date) | Starting download of Teams Backgrounds"
echo "############################################################"
echo ""

##
## Checking if Teams is Installed
##
while [[ $ready -ne 1 ]]; do
  missingappcount=0
  if [[ -e "$teamsapp" ]]; then
    echo "$(date) |  $teamsapp is installed"
  else
    let missingappcount=$missingappcount+1
  fi
  echo "$(date) |  [$missingappcount] application missing"

  if [[ $missingappcount -eq 0 ]]; then
    ready=1
    echo "$(date) |  Teams App found, lets download the backgrounds"
  else
    echo "$(date) |  Waiting for 10 seconds"
    sleep 10
  fi
done

##
## Checking if Teams Backgrounds Upload directory exists and create it if it's missing
##
if [[ -d ${teamsUpload} ]]; then
  echo "$(date) | Teams Background Upload dir [$teamsUpload] already exists"
else
  echo "$(date) | Creating [$teamsUpload]"
  mkdir -p "$teamsUpload"
fi

##
## Attempt to download the files. No point checking if it already exists since we want to overwrite it anyway
##
i=0
for backgroundurl in "${backgroundurls[@]}"; do
  ((i = i + 1))
  backgroundfile="TeamsBackground$i.png"
  echo "$(date) | Downloading Background from [$backgroundurl] to [$teamsUpload/$backgroundfile]"
  curl -L -o "$teamsUpload/$backgroundfile" $backgroundurl
  if [ "$?" = "0" ]; then
    echo "$(date) | Teams Background [$backgroundurl] downloaded to [$teamsUpload/$backgroundfile]"
  else
    echo "$(date) | Failed to download Teams Background image from [$backgroundurl]"
  fi
done

Time to add this into Intune and reap the rewards.

Intune Shell Scripts
#

As with everything Microsoft, there are some requirements and limitations with using Shell Scripts for macOS so have a read before you blindly start trying to push out scripts to your device estate. After you’ve read these requirements, create a new Shell Script with the below settings.

Setting Value
Shell script downloadTeamsBackground.sh
File contents Uploaded Script
Run script as signed-in user Yes
Hide script notifications on devices Not Configured
Script frequency Not Configured
Max number of times to retry if script fails 3 times

Looking a little like the below.

Shell Script
macOS Shell Script in Microsoft Intune.

Now we’ve added the Shell Script, this can be deployed to the ‘All Users’, ‘All Devices’ groups (Don’t do this as we don’t have Device Filters to use) or Groups of your choosing.

Checking Microsoft Teams
#

With the Script deployed from Intune and assigned to a group of devices, we can check on the devices themselves to make sure that the script has run successfully using the log file, checking that the new backgrounds have downloaded to the correct directory, and that these backgrounds appear in Microsoft Teams.

Script Logging
#

As per the configured variable in the script, we can find the log $HOME/Library/Logs/Microsoft/Intune/Scripts/SetTeamsBackground/SetTeamsBackground.log, opening it we can check on the status of the downloads.

Script Log
macOS Shell Script logging on a targeted device.

Everything looks solid we should check the download directory.

Background Directory
#

As we can see three files in the Uploads directory, all named appropriately.

Teams Directory
Teams background folder and contents on a targeted device.

Teams Background Effects
#

Last check is in a Microsoft Teams meeting.

Teams Backgrounds
Teams backgrounds within a Teams meeting.

All good here as well, we can relax and have a coffee.

If Microsoft Teams was open when the backgrounds were deployed, it will need a restart to pick up the new backgrounds. I did think about force quitting the app, but didn’t think users would appreciate that.

Summary
#

This was a pretty straight forward method to deploy backgrounds to Microsoft Teams using Intune Shell Scripts, and not a bad start to my journey into advanced management of macOS devices (despite actually being a macOS user). I’d recommend familiarising yourself with the Intune Shell Samples, as this is where started when hacking about with Shell scripts for macOS devices.

Or you could just pay for Microsoft Teams Premium, but where’s the fun in that?

Related

Updating Apple Operating System Compliance Policies
· loading
Microsoft Intune iOS/iPadOS macOS Compliance Software Updates Graph API PowerShell Automation
Device Migration and Automated Device Enrolment Profile Assignment
· loading
Microsoft Intune iOS/iPadOS macOS Device Enrolment Graph API PowerShell Automated Device Enrolment Automation
Assigning Intune Mobile Apps Quickly and Consistently
· loading
Microsoft Intune Android iOS/iPadOS Administration Apps Graph API PowerShell Automation