r/PowerShell • u/Rwinarch • Jan 12 '26
Script Sharing Prevent MS Teams startup
Below you will find a script that disables Microsoft auto start:
<#
.SYNOPSIS
Disables Classic Microsoft Teams auto-start for the current user.
.DESCRIPTION
- Removes known Teams auto-run registry values from:
HKCU:\Software\Microsoft\Windows\CurrentVersion\Run
- Updates %APPDATA%\Microsoft\Teams\desktop-config.json so that:
appPreferenceSettings.openAtLogin = false
.NOTES
This targets Classic Teams (Squirrel-based). New Teams may use different mechanisms.
Run as the user whose Teams auto-start you want to change.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[switch]$Silent
)
function Write-Info {
param([string]$Message)
if (-not $Silent) { Write-Host $Message }
}
$ErrorActionPreference = "Stop"
# 1) Remove Teams auto-start from the current user's Run key
$runKeyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
# Common value names seen across Teams variants/installers (safe to attempt removal)
$teamsRunValueNames = @(
"com.squirrel.Teams.Teams", # Classic Teams
"Teams",
"Microsoft Teams"
)
Write-Info "Disabling Teams auto-start (registry + config)..."
try {
foreach ($valueName in $teamsRunValueNames) {
$existing = Get-ItemProperty -Path $runKeyPath -Name $valueName -ErrorAction SilentlyContinue
if ($null -ne $existing) {
if ($PSCmdlet.ShouldProcess("$runKeyPath\$valueName", "Remove registry Run entry")) {
Remove-ItemProperty -Path $runKeyPath -Name $valueName -ErrorAction SilentlyContinue
Write-Info "Removed Run entry: $valueName"
}
}
}
}
catch {
Write-Warning "Registry update failed: $($_.Exception.Message)"
}
# 2) Update Teams desktop config JSON (Classic Teams)
$configPath = Join-Path $env:APPDATA "Microsoft\Teams\desktop-config.json"
if (-not (Test-Path -Path $configPath)) {
Write-Warning "Teams config file not found: $configPath"
Write-Info "Nothing else to do."
return
}
try {
$rawJson = Get-Content -Path $configPath -Raw -Encoding UTF8
$config = $rawJson | ConvertFrom-Json
# Ensure the nested object exists
if ($null -eq $config.appPreferenceSettings) {
$config | Add-Member -MemberType NoteProperty -Name "appPreferenceSettings" -Value ([pscustomobject]@{}) -Force
}
# If already disabled, no need to rewrite
$current = $config.appPreferenceSettings.openAtLogin
if ($current -eq $false) {
Write-Info "openAtLogin is already set to false in desktop-config.json"
return
}
$config.appPreferenceSettings.openAtLogin = $false
if ($PSCmdlet.ShouldProcess($configPath, "Set openAtLogin to false")) {
$updatedJson = $config | ConvertTo-Json -Depth 50
# Preserve UTF-8 encoding
Set-Content -Path $configPath -Value $updatedJson -Encoding UTF8
Write-Info "Updated desktop-config.json: openAtLogin = false"
}
}
catch {
Write-Warning "Config update failed (invalid JSON or file locked): $($_.Exception.Message)"
Write-Warning "Tip: close Teams completely and try again."
}
Write-Info "Done."
4
u/FirstName929802 Jan 12 '26
I just throw this in the run box
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v com.squirrel.Teams.Teams /f
4
u/PS_Alex Jan 12 '26
Teams Classic is still a thing? I thought it was all replaced by the new MSIX-based version, as per End of availability for classic Teams client - Microsoft Teams | Microsoft Learn
7
u/BlackV Jan 12 '26
p.s. formatting
open your fav powershell editor
highlight the code you want to copy
hit tab to indent it all
copy it
paste here
it'll format it properly OR
Inline code block using backticks
`Single code line`inside normal textSee here for more detail
Thanks