Forum Discussion
Bulk deploy the Teams auto start setting
- May 17, 2025
Having not had a response here, I asked the same question in the Windows Office Hours yesterday. Didn't get a response there either. No big surprise.
So, I spent a few hours this afternoon trying to figure out if the potential solution I suggested would work. It does, sort of. The problem is it seems to take over 10 minutes for the Teams app to install in the user's profile after they sign in. As a workaround for that, the command I drop in the RunOnce key runs a PowerShell script that checks every 10 seconds to see whether "ms-teams" is a valid command. Once it is, it runs it. Pretty janky, but better than nothing, maybe?
Anyway, here is my Intune remediation detection script:
$detected = 0 $defaultRunOncePath = 'Default:\Software\Microsoft\Windows\CurrentVersion\RunOnce' if(-not (Get-ProvisionedAppxPackage -Online | Where-Object { $_.DisplayName -eq "MSTeams" })) { Write-Host 'Teams is not installed' Exit 0 } reg 'load' 'HKU\Default' 'C:\Users\Default\NTUSER.DAT' New-PSDrive -Name 'Default' -PSProvider Registry -Root 'HKU\Default' | Out-Null if(-not (Test-Path -Path 'Default:')) { Write-Error 'Could not load default user registry hive' Exit 0 } if ((Get-Item $defaultRunOncePath -ErrorAction Ignore).Property -contains 'ms-teams') { Write-Host 'The ms-teams reg value already exists in the default user RunOnce' $detected = 1 } else { Write-Host 'The ms-teams reg value was not found in the default user RunOnce' } Remove-PSDrive -Name 'Default' [GC]::Collect() reg 'unload' 'HKU\Default' Exit $detected
And here's the remediation script:
$defaultRunOncePath = 'Default:\Software\Microsoft\Windows\CurrentVersion\RunOnce' $cmd = @" Powershell -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& { do {Start-Sleep 10} until (Get-Command ms-teams -ErrorAction SilentlyContinue); Start-Process ms-teams }" "@ reg 'load' 'HKU\Default' 'C:\Users\Default\NTUSER.DAT' New-PSDrive -Name 'Default' -PSProvider Registry -Root 'HKU\Default' | Out-Null if(-not (Test-Path -Path 'Default:')) { Write-Error 'Could not load default user registry hive' Exit 0 } if(-not (Test-Path -Path $defaultRunOncePath)) { New-Item -Path $defaultRunOncePath -Force } Set-ItemProperty -Path $defaultRunOncePath -Name 'ms-teams' -Value $cmd Remove-PSDrive -Name 'Default' [GC]::Collect() reg 'unload' 'HKU\Default'
Disclaimer: I haven't actually tried deploying this with Intune yet. I've only run the scripts directly on my machine. Use at your own risk, obviously.
Having not had a response here, I asked the same question in the Windows Office Hours yesterday. Didn't get a response there either. No big surprise.
So, I spent a few hours this afternoon trying to figure out if the potential solution I suggested would work. It does, sort of. The problem is it seems to take over 10 minutes for the Teams app to install in the user's profile after they sign in. As a workaround for that, the command I drop in the RunOnce key runs a PowerShell script that checks every 10 seconds to see whether "ms-teams" is a valid command. Once it is, it runs it. Pretty janky, but better than nothing, maybe?
Anyway, here is my Intune remediation detection script:
$detected = 0
$defaultRunOncePath = 'Default:\Software\Microsoft\Windows\CurrentVersion\RunOnce'
if(-not (Get-ProvisionedAppxPackage -Online | Where-Object { $_.DisplayName -eq "MSTeams" })) {
Write-Host 'Teams is not installed'
Exit 0
}
reg 'load' 'HKU\Default' 'C:\Users\Default\NTUSER.DAT'
New-PSDrive -Name 'Default' -PSProvider Registry -Root 'HKU\Default' | Out-Null
if(-not (Test-Path -Path 'Default:')) {
Write-Error 'Could not load default user registry hive'
Exit 0
}
if ((Get-Item $defaultRunOncePath -ErrorAction Ignore).Property -contains 'ms-teams') {
Write-Host 'The ms-teams reg value already exists in the default user RunOnce'
$detected = 1
} else {
Write-Host 'The ms-teams reg value was not found in the default user RunOnce'
}
Remove-PSDrive -Name 'Default'
[GC]::Collect()
reg 'unload' 'HKU\Default'
Exit $detected
And here's the remediation script:
$defaultRunOncePath = 'Default:\Software\Microsoft\Windows\CurrentVersion\RunOnce'
$cmd = @"
Powershell -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& { do {Start-Sleep 10} until (Get-Command ms-teams -ErrorAction SilentlyContinue); Start-Process ms-teams }"
"@
reg 'load' 'HKU\Default' 'C:\Users\Default\NTUSER.DAT'
New-PSDrive -Name 'Default' -PSProvider Registry -Root 'HKU\Default' | Out-Null
if(-not (Test-Path -Path 'Default:')) {
Write-Error 'Could not load default user registry hive'
Exit 0
}
if(-not (Test-Path -Path $defaultRunOncePath)) {
New-Item -Path $defaultRunOncePath -Force
}
Set-ItemProperty -Path $defaultRunOncePath -Name 'ms-teams' -Value $cmd
Remove-PSDrive -Name 'Default'
[GC]::Collect()
reg 'unload' 'HKU\Default'
Disclaimer: I haven't actually tried deploying this with Intune yet. I've only run the scripts directly on my machine. Use at your own risk, obviously.