add
add script
This commit is contained in:
1 parent
1c97f2d498
commit
a59992bae8
15 files changed
+1175
No files matched your search
@@ -0,0 +1,124 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - DETECTION script.
|
||||
Prueft, ob Microsoft Teams (klassisch und/oder "neues Teams") noch per
|
||||
Autostart sofort mit der Anmeldung startet, und ob der verzoegerte Start
|
||||
(Autostart-Verknuepfung + PowerShell-Launcher) bereits eingerichtet ist.
|
||||
|
||||
.DESCRIPTION
|
||||
Exit 0 = konform -> Remediate-TeamsAutostart.ps1 wird NICHT ausgefuehrt
|
||||
Exit 1 = nicht konform -> Remediate-TeamsAutostart.ps1 wird ausgefuehrt
|
||||
|
||||
.NOTES
|
||||
Intune-Einstellungen fuer dieses Skript (Devices > Scripts and remediations):
|
||||
Run this script using the logged-on credentials : YES (zwingend, wegen HKCU/%APPDATA%)
|
||||
Enforce script signature check : No (ausser ihr signiert es)
|
||||
Run script in 64-bit PowerShell Host : Yes
|
||||
|
||||
Muss zu den gleichen Datei-/Verknuepfungsnamen wie im Remediation-Skript
|
||||
passen (auf Scheduled Tasks und VBScript wird bewusst NICHT geprueft: Task
|
||||
Scheduler ist auf vielen verwalteten Geraeten fuer Nicht-Admins per
|
||||
Richtlinie gesperrt, und Windows Script Host oft per ASR-Regel blockiert).
|
||||
#>
|
||||
|
||||
param(
|
||||
[string]$LnkFileName = "Microsoft Teams (Delayed Start).lnk",
|
||||
[string]$LauncherPath = (Join-Path $env:LOCALAPPDATA "TeamsDelayedStart\Start-TeamsDelayed.ps1")
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
$nonCompliant = $false
|
||||
|
||||
# --- 1) Klassisches Teams: Run-Key -----------------------------------------
|
||||
$runKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
|
||||
if (Get-ItemProperty -Path $runKey -Name "com.squirrel.Teams.Teams" -ErrorAction SilentlyContinue) {
|
||||
Write-Output "Nicht konform: Klassisches Teams - Run-Key Autostart ist aktiv."
|
||||
$nonCompliant = $true
|
||||
}
|
||||
|
||||
# --- 2) Klassisches Teams: desktop-config.json ------------------------------
|
||||
$configPath = Join-Path $env:APPDATA "Microsoft\Teams\desktop-config.json"
|
||||
if (Test-Path $configPath) {
|
||||
try {
|
||||
$json = Get-Content $configPath -Raw | ConvertFrom-Json
|
||||
if ($json.appPreferenceSettings.openAtLogin -eq $true) {
|
||||
Write-Output "Nicht konform: Klassisches Teams - openAtLogin=true in desktop-config.json."
|
||||
$nonCompliant = $true
|
||||
}
|
||||
} catch {
|
||||
Write-Output "Warnung: desktop-config.json konnte nicht gelesen werden ($_)."
|
||||
}
|
||||
}
|
||||
|
||||
# --- 3) Neues Teams (MSIX): StartupTask State in der Registry --------------
|
||||
# State-Werte entsprechen der WinRT StartupTaskState-Enum:
|
||||
# 0 = Disabled, 1 = DisabledByUser, 2 = Enabled, 3 = DisabledByPolicy, 4 = EnabledByPolicy
|
||||
# WICHTIG: Nur Unterschluessel pruefen, deren Name "Startup" enthaelt (z.B.
|
||||
# "TeamsTfwStartupTask"). Andere Unterschluessel (AppUriHandlers, SplashScreen,
|
||||
# Schemas, HAM, PSR, ...) sind normale App-Erweiterungen, die dauerhaft auf
|
||||
# State=2 stehen - die duerfen NICHT als "nicht konform" gewertet werden.
|
||||
$newTeamsBase = "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\MSTeams_8wekyb3d8bbwe"
|
||||
if (Test-Path $newTeamsBase) {
|
||||
Get-ChildItem -Path $newTeamsBase -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match 'Startup' } | ForEach-Object {
|
||||
$state = (Get-ItemProperty -Path $_.PSPath -Name "State" -ErrorAction SilentlyContinue).State
|
||||
if ($state -eq 2) {
|
||||
Write-Output "Nicht konform: Neues Teams - StartupTask '$($_.PSChildName)' ist aktiviert (State=2)."
|
||||
$nonCompliant = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# --- 4) Fremde Autostart-Verknuepfungen im Startup-Ordner -------------------
|
||||
# Unsere eigene Verzoegerungs-Verknuepfung ($LnkFileName, siehe Abschnitt 5)
|
||||
# enthaelt ebenfalls "Teams" im Namen und darf hier NICHT als "fremd" gewertet
|
||||
# werden.
|
||||
$startupFolders = @(
|
||||
(Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\Startup"),
|
||||
(Join-Path $env:ProgramData "Microsoft\Windows\Start Menu\Programs\StartUp")
|
||||
)
|
||||
foreach ($folder in $startupFolders) {
|
||||
if (Test-Path $folder) {
|
||||
$lnk = Get-ChildItem -Path $folder -Filter "*Teams*.lnk" -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.Name -ne $LnkFileName }
|
||||
if ($lnk) {
|
||||
Write-Output "Nicht konform: Fremde Autostart-Verknuepfung(en) gefunden in $folder."
|
||||
$nonCompliant = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# --- 5) Verzoegerter Start (Verknuepfung + Launcher-Skript) muss existieren
|
||||
# und auf die aktuell installierte Teams-Version zeigen -------------
|
||||
$lnkPath = Join-Path $startupFolders[0] $LnkFileName
|
||||
|
||||
if (-not (Test-Path $lnkPath)) {
|
||||
Write-Output "Nicht konform: Autostart-Verknuepfung ('$lnkPath') existiert nicht."
|
||||
$nonCompliant = $true
|
||||
} elseif (-not (Test-Path $LauncherPath)) {
|
||||
Write-Output "Nicht konform: Launcher-Skript ('$LauncherPath') existiert nicht."
|
||||
$nonCompliant = $true
|
||||
} else {
|
||||
$expectedFragment = $null
|
||||
$startApp = Get-StartApps | Where-Object { $_.Name -match '^Microsoft Teams$|^Teams$' } | Select-Object -First 1
|
||||
if ($startApp) {
|
||||
$expectedFragment = "shell:appsFolder\$($startApp.AppID)"
|
||||
} else {
|
||||
$classicExe = Join-Path $env:LOCALAPPDATA "Microsoft\Teams\current\Teams.exe"
|
||||
if (Test-Path $classicExe) { $expectedFragment = $classicExe }
|
||||
}
|
||||
|
||||
if ($expectedFragment) {
|
||||
$launcherText = Get-Content -Path $LauncherPath -Raw -ErrorAction SilentlyContinue
|
||||
if ($launcherText -notmatch [regex]::Escape($expectedFragment)) {
|
||||
Write-Output "Nicht konform: Verzoegerter Start zeigt nicht (mehr) auf die aktuelle Teams-Installation."
|
||||
$nonCompliant = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nonCompliant) {
|
||||
exit 1
|
||||
} else {
|
||||
Write-Output "Konform: Teams-Autostart entfernt, verzoegerter Start aktiv."
|
||||
exit 0
|
||||
}
|
||||
Reference in new issue
Block a user