I had been working on a Windows hardened Windows build which had Microsoft 365 Apps for Enterprise deployed to it but Teams was failing to be installed for users on first logon.

The installation file was successfully being copied into Program Files (x86) but unfortunately there seemed to be an issue with the process that executed it when a user logged on.

As a result I looked at alternatives to ensure users had Teams installed. I decided to create a scheduled task that would run at user logon and install command that should have been run automatically. Fortunately the teams install command has an option to check for installation so it won’t keep installing it.

As the machines are managed through Microsoft Endpoint Manager I created a Win32app package with contain the following script:

# Create log file location
$dest = "$($env:ProgramData)\Intune\scripts"
if (-not (Test-Path $dest)){mkdir $dest}
# Start transcript
start-transcript "$dest\Teams_install_task.log" -Append
# Only run if task does not already exist
if ( -not(Get-ScheduledTask -TaskName 'Teams User Install' -ErrorAction SilentlyContinue)) {
# Define location of Teams installer 
$Exe = "C:\Program Files (x86)\Teams Installer\teams.exe" 
# Set variables used in task
$timespan = New-Timespan -minutes 5
$InstallerArgs = "-checkInstall -source=ProPlus"
# Set task properties
$newScheduledTaskSplat = @{
        Action      = New-ScheduledTaskAction -Execute $Exe -Argument $InstallerArgs
        Description = 'Start the Teams installer for the currently logged on user'
        Settings    = New-ScheduledTaskSettingsSet -Compatibility Vista -AllowStartIfOnBatteries -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Hours 1)
        Trigger     = New-ScheduledTaskTrigger -AtLogOn -RandomDelay $timespan
        Principal   = New-ScheduledTaskPrincipal -GroupId 'S-1-5-32-545' -RunLevel Limited
    }
# Create task    
$ScheduledTask = New-ScheduledTask @newScheduledTaskSplat
Register-ScheduledTask -InputObject $ScheduledTask -TaskName 'Teams User Install'
}
stop-transcript

The advantage of deploying this as a Win32app is that we can properly detect if the task has been created, or if it needs to be, so to do this I created a simple detection script:

if ((Get-ScheduledTask -TaskName 'Teams User Install' -ErrorAction SilentlyContinue)) {write-host "Task Found"}

Hope this helps.

About the author