Skip to main content
r/PowerShell icon

r/PowerShell

members
online

Need to create scheduled tasks for all users Need to create scheduled tasks for all users

Hi all -

I functionally need to create a scheduled task every hour, regardless of whoever is logged in on the computer. I also have other scheduled tasks that will also run, but will need to be created disabled.

Generally: Task A, once certain parameters are met, will disable itself and then trigger task be at next startup. When Task B executes, it'll disable itself and then enable task C for every logon.

I've gotten it to work, more or less, when installing via Intune but the problem I'm running into is if Bob installs it and logs out, then when Sarah logs in the tasks aren't in her task scheduler.

Looking for all other options as well. Thanks!


60% of work is lost to context switching
Image 60% of work is lost to context switching



Prevent MS Teams startup Prevent MS Teams startup
Script Sharing

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."