add
add script
This commit is contained in:
1 parent
1c97f2d498
commit
a59992bae8
15 files changed
+1175
No files matched your search
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - Detection Script
|
||||
Prueft, ob im Autostart-Ordner des angemeldeten Benutzers eine
|
||||
Verknuepfung (.lnk) fuer die Zieldatei existiert.
|
||||
|
||||
.DESCRIPTION
|
||||
Gehoert zusammen mit "Remediate-StartFile.ps1" als Paar in ein Intune
|
||||
Proactive-Remediations-Paket. Es wird ausschliesslich anhand des
|
||||
Dateinamens geprueft, ob eine Verknuepfung mit passendem Namen im
|
||||
Autostart-Ordner liegt (z. B. fuer "Datei.exe" wird nach "Datei.lnk"
|
||||
gesucht).
|
||||
|
||||
WICHTIG ZUM AUSFUEHRUNGSKONTEXT:
|
||||
Der Autostart-Ordner wird ueber [Environment]::GetFolderPath('Startup')
|
||||
ermittelt, also der Autostart-Ordner des Benutzerkontexts, in dem dieses
|
||||
Skript laeuft (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup).
|
||||
Damit das der Ordner des angemeldeten Benutzers ist (und nicht der von
|
||||
SYSTEM), MUSS im Intune-Remediation-Paket fuer dieses Skript die Option
|
||||
"Run this script using the logged-on credentials" aktiviert sein
|
||||
(genauso wie beim zugehoerigen Remediation Script).
|
||||
|
||||
$FilePath muss exakt mit dem Wert im Remediation Script
|
||||
(Remediate-StartFile.ps1) uebereinstimmen.
|
||||
|
||||
.NOTES
|
||||
Exit-Code 0 = konform, keine Remediation noetig (Verknuepfung vorhanden)
|
||||
Exit-Code 1 = nicht konform, Remediation wird ausgefuehrt (Verknuepfung fehlt)
|
||||
#>
|
||||
|
||||
# ============================================================
|
||||
# KONFIGURATION - muss mit Remediate-StartFile.ps1 uebereinstimmen
|
||||
# ============================================================
|
||||
|
||||
$FilePath = "C:\Program Files (x86)\inSign UPad-Bridge\Insign Upad Bridge.exe"
|
||||
|
||||
# ============================================================
|
||||
# AUSFUEHRUNG - in der Regel nicht anpassen
|
||||
# ============================================================
|
||||
|
||||
try {
|
||||
$ShortcutName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath) + ".lnk"
|
||||
$StartupFolder = [Environment]::GetFolderPath('Startup')
|
||||
$ShortcutPath = Join-Path -Path $StartupFolder -ChildPath $ShortcutName
|
||||
|
||||
if (Test-Path -LiteralPath $ShortcutPath) {
|
||||
Write-Output "Konform: Autostart-Verknuepfung gefunden unter '$ShortcutPath'."
|
||||
exit 0
|
||||
}
|
||||
else {
|
||||
Write-Output "Nicht konform: Autostart-Verknuepfung nicht gefunden unter '$ShortcutPath'."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Output "Fehler bei der Erkennung: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - Detection Script
|
||||
Prueft, ob im Autostart-Ordner des angemeldeten Benutzers eine
|
||||
Verknuepfung (.lnk) fuer die Zieldatei existiert.
|
||||
|
||||
.DESCRIPTION
|
||||
Gehoert zusammen mit "Remediate-StartFile.ps1" als Paar in ein Intune
|
||||
Proactive-Remediations-Paket. Es wird ausschliesslich anhand des
|
||||
Dateinamens geprueft, ob eine Verknuepfung mit passendem Namen im
|
||||
Autostart-Ordner liegt (z. B. fuer "Datei.exe" wird nach "Datei.lnk"
|
||||
gesucht).
|
||||
|
||||
WICHTIG ZUM AUSFUEHRUNGSKONTEXT:
|
||||
Der Autostart-Ordner wird ueber [Environment]::GetFolderPath('Startup')
|
||||
ermittelt, also der Autostart-Ordner des Benutzerkontexts, in dem dieses
|
||||
Skript laeuft (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup).
|
||||
Damit das der Ordner des angemeldeten Benutzers ist (und nicht der von
|
||||
SYSTEM), MUSS im Intune-Remediation-Paket fuer dieses Skript die Option
|
||||
"Run this script using the logged-on credentials" aktiviert sein
|
||||
(genauso wie beim zugehoerigen Remediation Script).
|
||||
|
||||
$FilePath muss exakt mit dem Wert im Remediation Script
|
||||
(Remediate-StartFile.ps1) uebereinstimmen.
|
||||
|
||||
.NOTES
|
||||
Exit-Code 0 = konform, keine Remediation noetig (Verknuepfung vorhanden)
|
||||
Exit-Code 1 = nicht konform, Remediation wird ausgefuehrt (Verknuepfung fehlt)
|
||||
#>
|
||||
|
||||
# ============================================================
|
||||
# KONFIGURATION - muss mit Remediate-StartFile.ps1 uebereinstimmen
|
||||
# ============================================================
|
||||
|
||||
$FilePath = "C:\Pfad\zur\Datei.exe"
|
||||
|
||||
# ============================================================
|
||||
# AUSFUEHRUNG - in der Regel nicht anpassen
|
||||
# ============================================================
|
||||
|
||||
try {
|
||||
$ShortcutName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath) + ".lnk"
|
||||
$StartupFolder = [Environment]::GetFolderPath('Startup')
|
||||
$ShortcutPath = Join-Path -Path $StartupFolder -ChildPath $ShortcutName
|
||||
|
||||
if (Test-Path -LiteralPath $ShortcutPath) {
|
||||
Write-Output "Konform: Autostart-Verknuepfung gefunden unter '$ShortcutPath'."
|
||||
exit 0
|
||||
}
|
||||
else {
|
||||
Write-Output "Nicht konform: Autostart-Verknuepfung nicht gefunden unter '$ShortcutPath'."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Output "Fehler bei der Erkennung: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - Remediation Script
|
||||
Legt bei Bedarf eine Autostart-Verknuepfung fuer eine definierte Datei an
|
||||
und startet die Datei anschliessend nach einer konfigurierbaren
|
||||
Verzoegerung.
|
||||
|
||||
.DESCRIPTION
|
||||
Gehoert zusammen mit "Detect-AutostartLink.ps1" als Paar in ein Intune
|
||||
Proactive-Remediations-Paket.
|
||||
|
||||
Ablauf:
|
||||
1. Prueft, ob die Zieldatei ($FilePath) vorhanden ist.
|
||||
2. Prueft, ob im Autostart-Ordner des angemeldeten Benutzers bereits
|
||||
eine Verknuepfung (.lnk) mit dem Namen des Dateinamens existiert.
|
||||
3. Fehlt die Verknuepfung, wird sie neu angelegt (Ziel = $FilePath,
|
||||
optional mit $Arguments).
|
||||
4. Wartet $DelaySeconds Sekunden.
|
||||
5. Startet die Datei.
|
||||
|
||||
WICHTIG ZUM AUSFUEHRUNGSKONTEXT:
|
||||
Der Autostart-Ordner wird ueber [Environment]::GetFolderPath('Startup')
|
||||
ermittelt, also den Autostart-Ordner des Benutzerkontexts, in dem dieses
|
||||
Skript laeuft (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup).
|
||||
Damit das der Ordner des angemeldeten Benutzers ist (und nicht der von
|
||||
SYSTEM), MUSS im Intune-Remediation-Paket fuer dieses Skript die Option
|
||||
"Run this script using the logged-on credentials" aktiviert sein.
|
||||
|
||||
$FilePath, $Arguments und $DelaySeconds muessen mit den Werten im
|
||||
zugehoerigen Detection Script (Detect-AutostartLink.ps1) uebereinstimmen,
|
||||
damit beide Skripte dieselbe Verknuepfung betrachten.
|
||||
|
||||
.NOTES
|
||||
Exit-Code 0 = Remediation erfolgreich
|
||||
Exit-Code 1 = Remediation fehlgeschlagen
|
||||
#>
|
||||
|
||||
# ============================================================
|
||||
# KONFIGURATION - hier anpassen (muss zu Detect-AutostartLink.ps1 passen)
|
||||
# ============================================================
|
||||
|
||||
# Vollstaendiger Pfad zur Datei, fuer die eine Autostart-Verknuepfung
|
||||
# angelegt und die anschliessend gestartet werden soll
|
||||
$FilePath = "C:\Program Files (x86)\inSign UPad-Bridge\Insign Upad Bridge.exe"
|
||||
|
||||
# Optionale Argumente/Parameter fuer die Datei (leer lassen, falls nicht benoetigt)
|
||||
# Werden sowohl in der Verknuepfung als auch beim direkten Start verwendet
|
||||
$Arguments = ""
|
||||
|
||||
# Startverzoegerung in Sekunden, bevor die Datei (nach dem Anlegen der
|
||||
# Verknuepfung) direkt gestartet wird
|
||||
$DelaySeconds = 60
|
||||
|
||||
# ============================================================
|
||||
# AUSFUEHRUNG - in der Regel nicht anpassen
|
||||
# ============================================================
|
||||
|
||||
try {
|
||||
if (-not (Test-Path -LiteralPath $FilePath)) {
|
||||
Write-Output "Remediation fehlgeschlagen: Datei nicht gefunden unter '$FilePath'."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$ShortcutName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath) + ".lnk"
|
||||
$StartupFolder = [Environment]::GetFolderPath('Startup')
|
||||
$ShortcutPath = Join-Path -Path $StartupFolder -ChildPath $ShortcutName
|
||||
|
||||
if (-not (Test-Path -LiteralPath $ShortcutPath)) {
|
||||
Write-Output "Autostart-Verknuepfung fehlt, lege '$ShortcutPath' an..."
|
||||
|
||||
$WScriptShell = New-Object -ComObject WScript.Shell
|
||||
$Shortcut = $WScriptShell.CreateShortcut($ShortcutPath)
|
||||
$Shortcut.TargetPath = $FilePath
|
||||
if (-not [string]::IsNullOrWhiteSpace($Arguments)) {
|
||||
$Shortcut.Arguments = $Arguments
|
||||
}
|
||||
$Shortcut.WorkingDirectory = Split-Path -Path $FilePath -Parent
|
||||
$Shortcut.Save()
|
||||
|
||||
Write-Output "Autostart-Verknuepfung wurde angelegt."
|
||||
}
|
||||
else {
|
||||
Write-Output "Autostart-Verknuepfung existiert bereits unter '$ShortcutPath'."
|
||||
}
|
||||
|
||||
Write-Output "Warte $DelaySeconds Sekunde(n), bevor '$FilePath' gestartet wird..."
|
||||
Start-Sleep -Seconds $DelaySeconds
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Arguments)) {
|
||||
Start-Process -FilePath $FilePath -ErrorAction Stop
|
||||
}
|
||||
else {
|
||||
Start-Process -FilePath $FilePath -ArgumentList $Arguments -ErrorAction Stop
|
||||
}
|
||||
|
||||
Write-Output "Remediation erfolgreich: '$FilePath' wurde gestartet."
|
||||
exit 0
|
||||
}
|
||||
catch {
|
||||
Write-Output "Remediation fehlgeschlagen: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - Remediation Script
|
||||
Legt bei Bedarf eine Autostart-Verknuepfung fuer eine definierte Datei an
|
||||
und startet die Datei anschliessend nach einer konfigurierbaren
|
||||
Verzoegerung.
|
||||
|
||||
.DESCRIPTION
|
||||
Gehoert zusammen mit "Detect-AutostartLink.ps1" als Paar in ein Intune
|
||||
Proactive-Remediations-Paket.
|
||||
|
||||
Ablauf:
|
||||
1. Prueft, ob die Zieldatei ($FilePath) vorhanden ist.
|
||||
2. Prueft, ob im Autostart-Ordner des angemeldeten Benutzers bereits
|
||||
eine Verknuepfung (.lnk) mit dem Namen des Dateinamens existiert.
|
||||
3. Fehlt die Verknuepfung, wird sie neu angelegt (Ziel = $FilePath,
|
||||
optional mit $Arguments).
|
||||
4. Wartet $DelaySeconds Sekunden.
|
||||
5. Startet die Datei.
|
||||
|
||||
WICHTIG ZUM AUSFUEHRUNGSKONTEXT:
|
||||
Der Autostart-Ordner wird ueber [Environment]::GetFolderPath('Startup')
|
||||
ermittelt, also den Autostart-Ordner des Benutzerkontexts, in dem dieses
|
||||
Skript laeuft (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup).
|
||||
Damit das der Ordner des angemeldeten Benutzers ist (und nicht der von
|
||||
SYSTEM), MUSS im Intune-Remediation-Paket fuer dieses Skript die Option
|
||||
"Run this script using the logged-on credentials" aktiviert sein.
|
||||
|
||||
$FilePath, $Arguments und $DelaySeconds muessen mit den Werten im
|
||||
zugehoerigen Detection Script (Detect-AutostartLink.ps1) uebereinstimmen,
|
||||
damit beide Skripte dieselbe Verknuepfung betrachten.
|
||||
|
||||
.NOTES
|
||||
Exit-Code 0 = Remediation erfolgreich
|
||||
Exit-Code 1 = Remediation fehlgeschlagen
|
||||
#>
|
||||
|
||||
# ============================================================
|
||||
# KONFIGURATION - hier anpassen (muss zu Detect-AutostartLink.ps1 passen)
|
||||
# ============================================================
|
||||
|
||||
# Vollstaendiger Pfad zur Datei, fuer die eine Autostart-Verknuepfung
|
||||
# angelegt und die anschliessend gestartet werden soll
|
||||
$FilePath = "C:\Pfad\zur\Datei.exe"
|
||||
|
||||
# Optionale Argumente/Parameter fuer die Datei (leer lassen, falls nicht benoetigt)
|
||||
# Werden sowohl in der Verknuepfung als auch beim direkten Start verwendet
|
||||
$Arguments = ""
|
||||
|
||||
# Startverzoegerung in Sekunden, bevor die Datei (nach dem Anlegen der
|
||||
# Verknuepfung) direkt gestartet wird
|
||||
$DelaySeconds = 10
|
||||
|
||||
# ============================================================
|
||||
# AUSFUEHRUNG - in der Regel nicht anpassen
|
||||
# ============================================================
|
||||
|
||||
try {
|
||||
if (-not (Test-Path -LiteralPath $FilePath)) {
|
||||
Write-Output "Remediation fehlgeschlagen: Datei nicht gefunden unter '$FilePath'."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$ShortcutName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath) + ".lnk"
|
||||
$StartupFolder = [Environment]::GetFolderPath('Startup')
|
||||
$ShortcutPath = Join-Path -Path $StartupFolder -ChildPath $ShortcutName
|
||||
|
||||
if (-not (Test-Path -LiteralPath $ShortcutPath)) {
|
||||
Write-Output "Autostart-Verknuepfung fehlt, lege '$ShortcutPath' an..."
|
||||
|
||||
$WScriptShell = New-Object -ComObject WScript.Shell
|
||||
$Shortcut = $WScriptShell.CreateShortcut($ShortcutPath)
|
||||
$Shortcut.TargetPath = $FilePath
|
||||
if (-not [string]::IsNullOrWhiteSpace($Arguments)) {
|
||||
$Shortcut.Arguments = $Arguments
|
||||
}
|
||||
$Shortcut.WorkingDirectory = Split-Path -Path $FilePath -Parent
|
||||
$Shortcut.Save()
|
||||
|
||||
Write-Output "Autostart-Verknuepfung wurde angelegt."
|
||||
}
|
||||
else {
|
||||
Write-Output "Autostart-Verknuepfung existiert bereits unter '$ShortcutPath'."
|
||||
}
|
||||
|
||||
Write-Output "Warte $DelaySeconds Sekunde(n), bevor '$FilePath' gestartet wird..."
|
||||
Start-Sleep -Seconds $DelaySeconds
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Arguments)) {
|
||||
Start-Process -FilePath $FilePath -ErrorAction Stop
|
||||
}
|
||||
else {
|
||||
Start-Process -FilePath $FilePath -ArgumentList $Arguments -ErrorAction Stop
|
||||
}
|
||||
|
||||
Write-Output "Remediation erfolgreich: '$FilePath' wurde gestartet."
|
||||
exit 0
|
||||
}
|
||||
catch {
|
||||
Write-Output "Remediation fehlgeschlagen: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - Detection Script
|
||||
Erkennt, ob Brave Browser (System- oder Benutzerinstallation) TATSAECHLICH vorhanden ist.
|
||||
.DESCRIPTION
|
||||
Ein Uninstall-Registry-Eintrag zaehlt nur noch als Treffer, wenn die zugehoerige
|
||||
brave.exe / setup.exe auf der Platte existiert. Verwaiste Eintraege (z. B. nach
|
||||
einer Deinstallation ueber Brave selbst, waehrend der MSI-Wrapper-Eintrag stehen
|
||||
blieb, oder nach SYSTEM-Deinstallation einer Per-User-Installation) werden
|
||||
ignoriert und nur in der Ausgabe gemeldet.
|
||||
Die Ausgabe nennt immer die Fundstelle -> sichtbar in Intune unter
|
||||
"Ausgabe der Erkennung vor der Wartung".
|
||||
.NOTES
|
||||
Exit 0 = konform (Brave NICHT gefunden) -> keine Remediation
|
||||
Exit 1 = nicht konform (Brave gefunden) -> Remediation wird ausgefuehrt
|
||||
Intune: Ausfuehrung als System, "Skript in 64-Bit-PowerShell ausfuehren" = Ja
|
||||
(falls nicht gesetzt, startet sich das Skript selbst in 64-Bit neu).
|
||||
#>
|
||||
|
||||
# In 32-Bit-PowerShell (Intune-Default) wird HKLM\SOFTWARE auf WOW6432Node umgeleitet
|
||||
# -> 64-Bit-Uninstall-Key waere unsichtbar. Daher in 64-Bit-Host neu starten.
|
||||
if ($env:PROCESSOR_ARCHITEW6432 -eq 'AMD64' -and $PSCommandPath) {
|
||||
& "$env:WINDIR\sysnative\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File $PSCommandPath
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
$uninstallSub = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
|
||||
$findings = New-Object System.Collections.Generic.List[string]
|
||||
$orphans = New-Object System.Collections.Generic.List[string]
|
||||
|
||||
function Get-ExePathFromString([string]$s) {
|
||||
if ([string]::IsNullOrWhiteSpace($s)) { return $null }
|
||||
$s = [Environment]::ExpandEnvironmentVariables($s.Trim())
|
||||
if ($s -match '^"([^"]+)"') { return $Matches[1] } # "C:\...\setup.exe" --uninstall
|
||||
if ($s -match '^(.+?\.exe)') { return $Matches[1] } # C:\...\brave.exe,0
|
||||
return $null
|
||||
}
|
||||
|
||||
# Liefert den Pfad, der die Installation belegt, oder $null (= verwaister Eintrag)
|
||||
function Get-BraveEntryProof($entry) {
|
||||
$candidates = @()
|
||||
$candidates += Get-ExePathFromString $entry.DisplayIcon
|
||||
if ($entry.InstallLocation) { $candidates += (Join-Path $entry.InstallLocation 'brave.exe') }
|
||||
$u = Get-ExePathFromString $entry.UninstallString
|
||||
if ($u -and $u -notmatch '(?i)msiexec') { $candidates += $u } # MSI-Eintraege nur ueber Dateisystem-Check
|
||||
foreach ($c in $candidates) {
|
||||
if ($c -and (Test-Path -LiteralPath $c -PathType Leaf)) { return $c }
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Test-UninstallKey([string]$keyPath, [string]$label) {
|
||||
Get-ItemProperty -Path "$keyPath\*" -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.DisplayName -like 'Brave*' } |
|
||||
ForEach-Object {
|
||||
$proof = Get-BraveEntryProof $_
|
||||
if ($proof) { $findings.Add("$label '$($_.DisplayName)' -> $proof") }
|
||||
else { $orphans.Add("$label '$($_.DisplayName)' [$($_.PSChildName)]") }
|
||||
}
|
||||
}
|
||||
|
||||
# 1) Systemweit (64-Bit und 32-Bit-Ansicht)
|
||||
Test-UninstallKey "Registry::HKEY_LOCAL_MACHINE\$uninstallSub" 'HKLM'
|
||||
Test-UninstallKey "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" 'HKLM-WOW64'
|
||||
|
||||
# 2) Geladene Benutzer-Hives (inkl. eigener Hive bei Ausfuehrung im Benutzerkontext)
|
||||
$loadedSids = @()
|
||||
Get-ChildItem 'Registry::HKEY_USERS' -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
$sid = $_.PSChildName
|
||||
if ($sid -match '^S-1-5-21-\d+-\d+-\d+-\d+$') {
|
||||
$loadedSids += $sid
|
||||
Test-UninstallKey "Registry::HKEY_USERS\$sid\$uninstallSub" "HKU\$sid"
|
||||
}
|
||||
}
|
||||
|
||||
# 3) Nicht geladene Profile: NTUSER.DAT temporaer mounten
|
||||
$profilePaths = @()
|
||||
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
$sid = $_.PSChildName
|
||||
if ($sid -notmatch '^S-1-5-21-\d+-\d+-\d+-\d+$') { return }
|
||||
$profilePath = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).ProfileImagePath
|
||||
if ($profilePath) { $profilePaths += $profilePath }
|
||||
if ($loadedSids -contains $sid) { return }
|
||||
|
||||
$ntUserDat = Join-Path $profilePath 'NTUSER.DAT'
|
||||
if (-not (Test-Path -LiteralPath $ntUserDat)) { return }
|
||||
|
||||
$mount = "HKU\TempBraveCheck_$sid"
|
||||
& reg.exe load $mount "$ntUserDat" 2>$null | Out-Null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
try {
|
||||
Test-UninstallKey "Registry::HKEY_USERS\TempBraveCheck_$sid\$uninstallSub" "Offline\$sid"
|
||||
} finally {
|
||||
[gc]::Collect(); [gc]::WaitForPendingFinalizers()
|
||||
& reg.exe unload $mount 2>$null | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 4) Dateisystem: Standardpfade + alle Profilordner
|
||||
$exeCandidates = @(
|
||||
"$env:ProgramW6432\BraveSoftware\Brave-Browser\Application\brave.exe",
|
||||
"${env:ProgramFiles(x86)}\BraveSoftware\Brave-Browser\Application\brave.exe"
|
||||
)
|
||||
$profilePaths += (Get-ChildItem 'C:\Users' -Directory -ErrorAction SilentlyContinue).FullName
|
||||
foreach ($p in ($profilePaths | Where-Object { $_ } | Sort-Object -Unique)) {
|
||||
$exeCandidates += (Join-Path $p 'AppData\Local\BraveSoftware\Brave-Browser\Application\brave.exe')
|
||||
}
|
||||
foreach ($exe in ($exeCandidates | Where-Object { $_ } | Sort-Object -Unique)) {
|
||||
if (Test-Path -LiteralPath $exe -PathType Leaf) {
|
||||
if (-not ($findings | Where-Object { $_ -like "*$exe" })) { $findings.Add("Datei -> $exe") }
|
||||
}
|
||||
}
|
||||
|
||||
# Ergebnis (Intune erfasst max. ~2048 Zeichen)
|
||||
$orphanText = if ($orphans.Count) { ' | Verwaiste Eintraege (ignoriert): ' + ($orphans -join '; ') } else { '' }
|
||||
|
||||
if ($findings.Count -gt 0) {
|
||||
$msg = 'Brave gefunden: ' + ($findings -join '; ') + $orphanText
|
||||
Write-Output ($msg.Substring(0, [Math]::Min(2000, $msg.Length)))
|
||||
exit 1
|
||||
} else {
|
||||
$msg = 'Brave nicht gefunden - System konform.' + $orphanText
|
||||
Write-Output ($msg.Substring(0, [Math]::Min(2000, $msg.Length)))
|
||||
exit 0
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
PowerShell-Nachbau des "Intune Network Drive Mapping Tool" (Weatherlights).
|
||||
|
||||
.DESCRIPTION
|
||||
Liest die Laufwerkszuordnungen aus denselben Policy-Keys wie das Original
|
||||
(HKCU\Software\Policies\weatherlights.com\NetworkDriveMapping), damit die
|
||||
bestehende ADMX-/Intune-Konfiguration weiter genutzt werden kann.
|
||||
Fallback: die Liste $FallbackMappings unten.
|
||||
|
||||
Modi:
|
||||
(ohne Parameter) Laufwerke verbinden (läuft im Benutzerkontext)
|
||||
-Install Skript nach C:\ProgramData\DriveMapping kopieren und
|
||||
Aufgabe registrieren (als SYSTEM / Admin ausführen)
|
||||
-Uninstall Aufgabe, Startmenü-Verknüpfung und Skript entfernen
|
||||
-ShowResult Wie ohne Parameter, zeigt am Ende ein Ergebnisfenster
|
||||
(wird von der Startmenü-Verknüpfung genutzt)
|
||||
|
||||
Das Skript schreibt und löscht keine Registry-Werte und fasst nur die
|
||||
konfigurierten Laufwerksbuchstaben an.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$Install,
|
||||
[switch]$Uninstall,
|
||||
[switch]$ShowResult
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Einstellungen
|
||||
# ---------------------------------------------------------------------------
|
||||
$PolicyRoot = 'HKCU:\Software\Policies\weatherlights.com\NetworkDriveMapping'
|
||||
$InstallDir = Join-Path $env:ProgramData 'DriveMapping'
|
||||
$TaskName = 'Network Drive Mapping'
|
||||
$LogFile = Join-Path $env:LOCALAPPDATA 'DriveMapping\DriveMapping.log'
|
||||
# Startmenü für alle Benutzer (C:\ProgramData\Microsoft\Windows\Start Menu\Programs)
|
||||
$ShortcutPath = Join-Path ([Environment]::GetFolderPath('CommonPrograms')) 'Netzlaufwerke verbinden.lnk'
|
||||
|
||||
# Wird nur genutzt, wenn keine Policy-Keys vorhanden sind.
|
||||
# Umgebungsvariablen wie %USERNAME% werden aufgelöst.
|
||||
$FallbackMappings = @(
|
||||
# @{ Letter = 'H'; Path = '\\fileserver\home$\%USERNAME%' }
|
||||
# @{ Letter = 'S'; Path = '\\fileserver\shares' }
|
||||
)
|
||||
|
||||
$Defaults = @{
|
||||
Persistent = $false # MapPersistent
|
||||
RetryCount = 10 # Anzahl Versuche, bis der Server erreichbar ist
|
||||
RetryDelaySec = 6 # Wartezeit zwischen Versuchen
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Hilfsfunktionen
|
||||
# ---------------------------------------------------------------------------
|
||||
function Write-Log {
|
||||
param([string]$Message, [ValidateSet('INFO','WARN','ERROR')][string]$Level = 'INFO')
|
||||
$dir = Split-Path $LogFile
|
||||
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
|
||||
if ((Test-Path $LogFile) -and (Get-Item $LogFile).Length -gt 1MB) {
|
||||
Move-Item $LogFile "$LogFile.old" -Force
|
||||
}
|
||||
"{0:yyyy-MM-dd HH:mm:ss} [{1}] {2}" -f (Get-Date), $Level, $Message | Add-Content -Path $LogFile -Encoding UTF8
|
||||
}
|
||||
|
||||
function Show-Result {
|
||||
# Nur bei manuellem Start über die Verknüpfung (-ShowResult)
|
||||
param([string]$Text, [switch]$IsError)
|
||||
if (-not $ShowResult) { return }
|
||||
$icon = if ($IsError) { 48 } else { 64 } # 48 = Warnung, 64 = Info
|
||||
$shell = New-Object -ComObject WScript.Shell
|
||||
[void]$shell.Popup($Text, 30, 'Netzlaufwerke', $icon) # schließt nach 30 s von selbst
|
||||
}
|
||||
|
||||
function Get-PolicyValue {
|
||||
param([string]$Name, $Default)
|
||||
$v = (Get-ItemProperty -Path $PolicyRoot -Name $Name -ErrorAction SilentlyContinue).$Name
|
||||
if ($null -eq $v) { $Default } else { $v }
|
||||
}
|
||||
|
||||
function Get-DriveMappings {
|
||||
$list = @()
|
||||
|
||||
# Neues Format (ADMX >= 1.3.2.0): ...\Policies2\<Buchstabe> mit Path/Username/Password
|
||||
$p2 = Join-Path $PolicyRoot 'Policies2'
|
||||
if (Test-Path $p2) {
|
||||
foreach ($key in Get-ChildItem $p2) {
|
||||
$props = Get-ItemProperty $key.PSPath
|
||||
if ($props.Path) {
|
||||
$list += [pscustomobject]@{
|
||||
Letter = $key.PSChildName.TrimEnd(':').ToUpper()
|
||||
Path = $props.Path
|
||||
Username = $props.Username
|
||||
Password = $props.Password
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list
|
||||
}
|
||||
|
||||
# Altes Format: ...\Policies, Werte "Buchstabe;Pfad[;User;Passwort]"
|
||||
$p1 = Join-Path $PolicyRoot 'Policies'
|
||||
if (Test-Path $p1) {
|
||||
$item = Get-Item $p1
|
||||
foreach ($name in $item.GetValueNames()) {
|
||||
$parts = ([string]$item.GetValue($name)).Split(';')
|
||||
if ($parts.Count -ge 2) {
|
||||
$list += [pscustomobject]@{
|
||||
Letter = $parts[0].TrimEnd(':').ToUpper()
|
||||
Path = $parts[1]
|
||||
Username = if ($parts.Count -ge 4) { $parts[2] } else { $null }
|
||||
Password = if ($parts.Count -ge 4) { $parts[3] } else { $null }
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list
|
||||
}
|
||||
|
||||
# Fallback
|
||||
foreach ($m in $FallbackMappings) {
|
||||
$list += [pscustomobject]@{ Letter = $m.Letter.ToUpper(); Path = $m.Path; Username = $m.Username; Password = $m.Password }
|
||||
}
|
||||
return $list
|
||||
}
|
||||
|
||||
function Test-SmbReachable {
|
||||
param([string]$Server, [int]$TimeoutMs = 2000)
|
||||
$client = New-Object System.Net.Sockets.TcpClient
|
||||
try {
|
||||
$ar = $client.BeginConnect($Server, 445, $null, $null)
|
||||
if ($ar.AsyncWaitHandle.WaitOne($TimeoutMs) -and $client.Connected) { return $true }
|
||||
return $false
|
||||
} catch { return $false }
|
||||
finally { $client.Close() }
|
||||
}
|
||||
|
||||
function Get-CurrentMappings {
|
||||
# Liefert Hashtable Buchstabe -> UNC-Pfad der aktuell verbundenen Laufwerke
|
||||
$result = @{}
|
||||
$net = New-Object -ComObject WScript.Network
|
||||
$drives = $net.EnumNetworkDrives()
|
||||
for ($i = 0; $i -lt $drives.Count(); $i += 2) {
|
||||
$letter = $drives.Item($i).TrimEnd(':').ToUpper()
|
||||
if ($letter) { $result[$letter] = $drives.Item($i + 1) }
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Installation / Deinstallation (als SYSTEM bzw. Admin, z. B. Intune-Plattformskript)
|
||||
# ---------------------------------------------------------------------------
|
||||
if ($Install) {
|
||||
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
||||
$target = Join-Path $InstallDir 'Invoke-DriveMapping.ps1'
|
||||
Copy-Item -Path $PSCommandPath -Destination $target -Force
|
||||
|
||||
# Ohne sichtbares Fenster: conhost --headless (Win10 21H2+/Win11), sonst Fallback
|
||||
$psArgs = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$target`""
|
||||
$conhost = Join-Path $env:windir 'System32\conhost.exe'
|
||||
$action = New-ScheduledTaskAction -Execute $conhost -Argument "--headless powershell.exe $psArgs"
|
||||
|
||||
# Trigger 1: Anmeldung (jeder Benutzer)
|
||||
$tLogon = New-ScheduledTaskTrigger -AtLogOn
|
||||
$tLogon.Delay = 'PT15S'
|
||||
|
||||
# Trigger 2: Netzwerkverbindung hergestellt (NetworkProfile, Event 10000)
|
||||
$cls = Get-CimClass -Namespace Root/Microsoft/Windows/TaskScheduler -ClassName MSFT_TaskEventTrigger
|
||||
$tNet = New-CimInstance -CimClass $cls -ClientOnly
|
||||
$tNet.Enabled = $true
|
||||
$tNet.Delay = 'PT10S'
|
||||
$tNet.Subscription = '<QueryList><Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"><Select Path="Microsoft-Windows-NetworkProfile/Operational">*[System[EventID=10000]]</Select></Query></QueryList>'
|
||||
|
||||
# Läuft im Kontext des angemeldeten Benutzers (Gruppe "Benutzer", SID-basiert = sprachunabhängig)
|
||||
$principal = New-ScheduledTaskPrincipal -GroupId 'S-1-5-32-545' -RunLevel Limited
|
||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
|
||||
-ExecutionTimeLimit (New-TimeSpan -Minutes 10) -MultipleInstances IgnoreNew -StartWhenAvailable
|
||||
|
||||
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger @($tLogon, $tNet) `
|
||||
-Principal $principal -Settings $settings -Force | Out-Null
|
||||
|
||||
# Startmenü-Verknüpfung: startet das Skript im Benutzerkontext mit Ergebnisfenster
|
||||
$wsh = New-Object -ComObject WScript.Shell
|
||||
$lnk = $wsh.CreateShortcut($ShortcutPath)
|
||||
$lnk.TargetPath = $conhost
|
||||
$lnk.Arguments = "--headless powershell.exe $psArgs -ShowResult"
|
||||
$lnk.WorkingDirectory = $InstallDir
|
||||
$lnk.IconLocation = "$env:SystemRoot\System32\shell32.dll,9"
|
||||
$lnk.Description = 'Netzlaufwerke erneut verbinden'
|
||||
$lnk.Save()
|
||||
|
||||
Write-Output "Installiert: $target, Aufgabe '$TaskName' registriert, Verknüpfung $ShortcutPath angelegt."
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($Uninstall) {
|
||||
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path $ShortcutPath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path $InstallDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Write-Output "Aufgabe '$TaskName', Verknüpfung und $InstallDir entfernt."
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Laufwerke verbinden (Benutzerkontext)
|
||||
# ---------------------------------------------------------------------------
|
||||
$enabled = Get-PolicyValue -Name 'Enabled' -Default $null
|
||||
if ($null -ne $enabled -and [int]$enabled -eq 0) {
|
||||
Write-Log 'Policy "Enabled" = 0, nichts zu tun.'
|
||||
Show-Result 'Die Laufwerkszuordnung ist für dieses Gerät deaktiviert.' -IsError
|
||||
exit 0
|
||||
}
|
||||
|
||||
$persistent = [bool][int](Get-PolicyValue -Name 'MapPersistent' -Default ([int]$Defaults.Persistent))
|
||||
$retryCount = [int](Get-PolicyValue -Name 'RetryCount' -Default $Defaults.RetryCount)
|
||||
$mappings = @(Get-DriveMappings)
|
||||
|
||||
if ($mappings.Count -eq 0) {
|
||||
Write-Log 'Keine Laufwerkszuordnungen konfiguriert.' 'WARN'
|
||||
Show-Result "Es sind keine Netzlaufwerke konfiguriert.`nBitte an die IT wenden, falls Laufwerke fehlen." -IsError
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Log "Start: $($mappings.Count) Zuordnung(en), Persistent=$persistent, Benutzer=$env:USERNAME"
|
||||
$net = New-Object -ComObject WScript.Network
|
||||
$done = [System.Collections.Generic.List[string]]::new() # für das Ergebnisfenster
|
||||
$skipped = [System.Collections.Generic.List[string]]::new()
|
||||
$pending = [System.Collections.Generic.List[object]]::new()
|
||||
$mappings | ForEach-Object { $pending.Add($_) }
|
||||
|
||||
for ($attempt = 1; $attempt -le $retryCount -and $pending.Count -gt 0; $attempt++) {
|
||||
$current = Get-CurrentMappings
|
||||
|
||||
foreach ($m in @($pending)) {
|
||||
$path = [Environment]::ExpandEnvironmentVariables($m.Path).TrimEnd('\')
|
||||
$drive = "$($m.Letter):"
|
||||
|
||||
# Bereits korrekt verbunden?
|
||||
if ($current.ContainsKey($m.Letter) -and $current[$m.Letter].TrimEnd('\') -ieq $path) {
|
||||
Write-Log "$drive ist bereits mit $path verbunden."
|
||||
$done.Add("$drive $path")
|
||||
[void]$pending.Remove($m)
|
||||
continue
|
||||
}
|
||||
|
||||
$server = ($path -replace '^\\\\', '').Split('\')[0]
|
||||
if (-not (Test-SmbReachable -Server $server)) {
|
||||
Write-Log "Versuch $attempt/${retryCount}: $server (445) nicht erreichbar, $drive wird später erneut versucht." 'WARN'
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
# Nur den eigenen Buchstaben trennen, wenn er auf ein anderes Ziel zeigt
|
||||
if ($current.ContainsKey($m.Letter)) {
|
||||
Write-Log "$drive zeigt auf $($current[$m.Letter]), wird getrennt."
|
||||
$net.RemoveNetworkDrive($drive, $true, $true)
|
||||
}
|
||||
elseif (Test-Path "$drive\") {
|
||||
Write-Log "$drive ist durch ein lokales Laufwerk belegt, übersprungen." 'ERROR'
|
||||
$skipped.Add("$drive durch ein lokales Laufwerk belegt")
|
||||
[void]$pending.Remove($m)
|
||||
continue
|
||||
}
|
||||
|
||||
if ($m.Username -and $m.Password) {
|
||||
$net.MapNetworkDrive($drive, $path, $persistent, $m.Username, $m.Password)
|
||||
} else {
|
||||
$net.MapNetworkDrive($drive, $path, $persistent)
|
||||
}
|
||||
Write-Log "$drive -> $path verbunden."
|
||||
$done.Add("$drive $path")
|
||||
[void]$pending.Remove($m)
|
||||
}
|
||||
catch {
|
||||
Write-Log "Fehler beim Verbinden von $drive -> ${path}: $($_.Exception.Message)" 'ERROR'
|
||||
}
|
||||
}
|
||||
|
||||
if ($pending.Count -gt 0 -and $attempt -lt $retryCount) { Start-Sleep -Seconds $Defaults.RetryDelaySec }
|
||||
}
|
||||
|
||||
foreach ($m in $pending) { $skipped.Add("$($m.Letter): Server nicht erreichbar oder Fehler") }
|
||||
|
||||
$msg = ''
|
||||
if ($done.Count -gt 0) { $msg += "Verbunden:`n " + ($done -join "`n ") + "`n`n" }
|
||||
if ($skipped.Count -gt 0) { $msg += "Nicht verbunden:`n " + ($skipped -join "`n ") + "`n`nIm Büro oder per VPN erneut versuchen. Log: $LogFile" }
|
||||
|
||||
if ($pending.Count -gt 0) {
|
||||
Write-Log "Nicht verbunden: $(($pending | ForEach-Object { $_.Letter + ':' }) -join ', ')" 'ERROR'
|
||||
Show-Result $msg.Trim() -IsError
|
||||
exit 1
|
||||
}
|
||||
Write-Log 'Fertig.'
|
||||
Show-Result $msg.Trim() -IsError:($skipped.Count -gt 0)
|
||||
exit 0
|
||||
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Intune Proactive Remediation - REMEDIATION script.
|
||||
Entfernt Microsoft Teams (klassisch UND neues Teams) aus dem Windows-
|
||||
Autostart und richtet stattdessen einen verzoegerten Start ein
|
||||
(Standard: 2 Minuten nach der Anmeldung).
|
||||
|
||||
.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
|
||||
|
||||
WICHTIG - Mechanik des verzoegerten Starts:
|
||||
Auf verwalteten Geraeten mit eingeschraenkten Benutzerrechten ist das
|
||||
Anlegen von Scheduled Tasks fuer Nicht-Admins per Richtlinie oft komplett
|
||||
gesperrt (sowohl Register-ScheduledTask als auch schtasks.exe liefern
|
||||
dann "Zugriff verweigert" - das laesst sich nicht umgehen). VBScript
|
||||
wird ebenfalls bewusst vermieden, da Windows Script Host (wscript.exe)
|
||||
auf vielen verwalteten Geraeten per ASR-Regel/AppLocker/WDAC blockiert
|
||||
ist. Stattdessen: eine .lnk-Verknuepfung im PERSOENLICHEN Autostart-
|
||||
Ordner (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup), die
|
||||
versteckt ("-WindowStyle Hidden") ein kleines PowerShell-Launcher-
|
||||
Skript startet. Dieses wartet die Verzoegerung ab und startet dann
|
||||
Teams. Beides - Verknuepfung erzeugen und Skript schreiben - erfordert
|
||||
nur Schreibrechte im eigenen Benutzerprofil, keine Zusatzrechte.
|
||||
|
||||
Quellen/Vorgehen recherchiert und verifiziert (Registry-Pfade):
|
||||
- Klassisches Teams Run-Key "com.squirrel.Teams.Teams"
|
||||
- desktop-config.json / appPreferenceSettings.openAtLogin
|
||||
- Neues Teams StartupTask unter
|
||||
HKCU:\...\AppModel\SystemAppData\MSTeams_8wekyb3d8bbwe\<TaskId> (State-DWord),
|
||||
nur Unterschluessel mit "Startup" im Namen anfassen (siehe Abschnitt 3)
|
||||
- Paketierte App zuverlaessig starten via "explorer.exe shell:appsFolder\<AUMID>",
|
||||
AUMID dynamisch per Get-StartApps ermittelt statt hart codiert.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[int]$DelayMinutes = 2,
|
||||
[string]$LnkFileName = "Microsoft Teams (Delayed Start).lnk",
|
||||
[string]$LauncherPath = (Join-Path $env:LOCALAPPDATA "TeamsDelayedStart\Start-TeamsDelayed.ps1"),
|
||||
[string]$LegacyVbsFileName = "TeamsDelayedStart.vbs", # Migrations-Cleanup fruehere Version
|
||||
[string]$LegacyTaskName = "Delayed Start - Microsoft Teams" # nur fuer Best-effort-Cleanup alter Versuche
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
function Log { param($msg) Write-Output "[$(Get-Date -Format 'HH:mm:ss')] $msg" }
|
||||
|
||||
Log "=== Teams-Autostart-Remediation gestartet (User: $env:USERNAME) ==="
|
||||
|
||||
# Teams wird NICHT mehr pauschal beendet. Die Registry-Aenderungen (Run-Key,
|
||||
# neues Teams StartupTask) sind bei laufendem Teams unproblematisch - Teams
|
||||
# liest/schreibt diese Werte nicht waehrend des Betriebs. Nur die
|
||||
# desktop-config.json des KLASSISCHEN Teams-Clients wird von Teams selbst
|
||||
# periodisch bzw. beim Beenden neu geschrieben; nur dafuer wird der Prozess
|
||||
# unten (Abschnitt 2), gezielt und nur falls diese Datei ueberhaupt existiert,
|
||||
# kurz beendet.
|
||||
|
||||
$classicFound = $false
|
||||
$newFound = $false
|
||||
|
||||
# --- 1) Klassisches Teams: Run-Key entfernen --------------------------------
|
||||
$runKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
|
||||
if (Get-ItemProperty -Path $runKey -Name "com.squirrel.Teams.Teams" -ErrorAction SilentlyContinue) {
|
||||
Remove-ItemProperty -Path $runKey -Name "com.squirrel.Teams.Teams" -ErrorAction SilentlyContinue
|
||||
Log "Autostart-Eintrag 'com.squirrel.Teams.Teams' aus Run-Key entfernt."
|
||||
$classicFound = $true
|
||||
}
|
||||
|
||||
# Generischer Fallback: jeden Run-Wert entfernen, der auf Teams verweist
|
||||
$runItem = Get-Item -Path $runKey -ErrorAction SilentlyContinue
|
||||
if ($runItem) {
|
||||
foreach ($prop in $runItem.Property) {
|
||||
$val = (Get-ItemProperty -Path $runKey -Name $prop -ErrorAction SilentlyContinue).$prop
|
||||
if ($val -match 'Teams\.exe' -or $val -match 'ms-teams\.exe') {
|
||||
Remove-ItemProperty -Path $runKey -Name $prop -ErrorAction SilentlyContinue
|
||||
Log "Zusaetzlicher Autostart-Eintrag entfernt: $prop"
|
||||
$classicFound = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# --- 2) Klassisches Teams: desktop-config.json anpassen ---------------------
|
||||
# Nur hier wird Teams (klassisch) gezielt kurz beendet: der Client schreibt
|
||||
# diese Datei periodisch/beim Beenden selbst und wuerde unsere Aenderung sonst
|
||||
# ueberschreiben. Betrifft ausschliesslich den klassischen Client - falls nur
|
||||
# neues Teams installiert ist, existiert diese Datei nicht und nichts wird
|
||||
# beendet.
|
||||
$configPath = Join-Path $env:APPDATA "Microsoft\Teams\desktop-config.json"
|
||||
if (Test-Path $configPath) {
|
||||
$classicFound = $true
|
||||
|
||||
$classicProc = Get-Process -Name "Teams" -ErrorAction SilentlyContinue
|
||||
if ($classicProc) {
|
||||
Log "Klassisches Teams laeuft - wird kurz beendet, damit die Config-Aenderung nicht ueberschrieben wird."
|
||||
$classicProc | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
|
||||
try {
|
||||
$json = Get-Content $configPath -Raw | ConvertFrom-Json
|
||||
if ($json.PSObject.Properties.Name -contains 'appPreferenceSettings') {
|
||||
$json.appPreferenceSettings.openAtLogin = $false
|
||||
} else {
|
||||
$json | Add-Member -NotePropertyName appPreferenceSettings -NotePropertyValue ([pscustomobject]@{ openAtLogin = $false }) -Force
|
||||
}
|
||||
$json | ConvertTo-Json -Depth 20 | Set-Content -Path $configPath -Encoding UTF8
|
||||
Log "desktop-config.json aktualisiert: openAtLogin = false"
|
||||
} catch {
|
||||
Log "Warnung: desktop-config.json konnte nicht angepasst werden ($_)."
|
||||
}
|
||||
}
|
||||
|
||||
# --- 3) Neues Teams (MSIX): StartupTask in der Registry deaktivieren -------
|
||||
# WICHTIG: Unter diesem Package-Schluessel liegen NEBEN dem eigentlichen
|
||||
# Autostart-Eintrag auch andere App-Erweiterungen (z.B. AppUriHandlers fuer
|
||||
# msteams://-Links, SplashScreen, Schemas, HAM, PSR). Nur der Unterschluessel,
|
||||
# dessen Name "Startup" enthaelt (z.B. "TeamsTfwStartupTask"), steuert den
|
||||
# Autostart - NUR diesen anfassen, alle anderen unveraendert lassen!
|
||||
$newTeamsBase = "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\MSTeams_8wekyb3d8bbwe"
|
||||
if (Test-Path $newTeamsBase) {
|
||||
$startupTasks = Get-ChildItem -Path $newTeamsBase -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match 'Startup' }
|
||||
if ($startupTasks) {
|
||||
$newFound = $true
|
||||
$startupTasks | ForEach-Object {
|
||||
$epoch = [int][double]::Parse((Get-Date -UFormat %s))
|
||||
Set-ItemProperty -Path $_.PSPath -Name "State" -Value 0 -Type DWord -ErrorAction SilentlyContinue
|
||||
Set-ItemProperty -Path $_.PSPath -Name "LastDisabledTime" -Value $epoch -Type QWord -ErrorAction SilentlyContinue
|
||||
Log "Neues Teams: StartupTask '$($_.PSChildName)' auf State=0 (deaktiviert) gesetzt."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# --- 4) Fremde Autostart-Verknuepfungen entfernen ---------------------------
|
||||
# WICHTIG: Unsere EIGENE, weiter unten (Abschnitt 5) angelegte Verzoegerungs-
|
||||
# Verknuepfung ($LnkFileName) heisst ebenfalls auf "Teams" und darf hier NICHT
|
||||
# mitgeloescht werden - sonst wuerde sie sich bei jedem erneuten Lauf selbst
|
||||
# entfernen.
|
||||
$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) {
|
||||
Get-ChildItem -Path $folder -Filter "*Teams*.lnk" -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.Name -ne $LnkFileName } |
|
||||
ForEach-Object {
|
||||
Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue
|
||||
Log "Fremde Autostart-Verknuepfung entfernt: $($_.FullName)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Migrations-Cleanup: VBScript-Variante einer frueheren Skriptversion entfernen
|
||||
$legacyVbsPath = Join-Path $startupFolders[0] $LegacyVbsFileName
|
||||
if (Test-Path $legacyVbsPath) {
|
||||
Remove-Item $legacyVbsPath -Force -ErrorAction SilentlyContinue
|
||||
Log "Alte VBScript-Variante entfernt: $legacyVbsPath"
|
||||
}
|
||||
|
||||
if (-not $classicFound -and -not $newFound) {
|
||||
Log "Hinweis: Weder klassisches noch neues Teams wurde mit aktivem Autostart erkannt (evtl. bereits bereinigt)."
|
||||
}
|
||||
|
||||
# --- 5) Verzoegerten Start ueber Autostart-Verknuepfung + PS-Launcher ------
|
||||
Log "Ermittle Teams-Startbefehl fuer den verzoegerten Start..."
|
||||
$startApp = Get-StartApps | Where-Object { $_.Name -match '^Microsoft Teams$|^Teams$' } | Select-Object -First 1
|
||||
$classicExe = Join-Path $env:LOCALAPPDATA "Microsoft\Teams\current\Teams.exe"
|
||||
|
||||
if (-not $startApp -and -not (Test-Path $classicExe)) {
|
||||
Log "FEHLER: Keine Teams-Installation gefunden - verzoegerter Start wird nicht eingerichtet."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Best-effort: einen evtl. auf weniger restriktiven Geraeten vorher erstellten
|
||||
# Scheduled Task aus einer frueheren Skriptversion entfernen. Zugriffsfehler
|
||||
# hier sind erwartet/harmlos und werden ignoriert.
|
||||
& schtasks.exe /Delete /TN $LegacyTaskName /F 2>&1 | Out-Null
|
||||
|
||||
$delaySeconds = $DelayMinutes * 60
|
||||
|
||||
# --- 5a) Launcher-Skript schreiben (macht den eigentlichen Sleep + Start) --
|
||||
$launcherDir = Split-Path -Path $LauncherPath -Parent
|
||||
if (-not (Test-Path $launcherDir)) {
|
||||
New-Item -Path $launcherDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
if ($startApp) {
|
||||
# Einfache Escaping-Vorkehrung fuer den seltenen Fall eines Apostrophs im AUMID
|
||||
$aumidEscaped = $startApp.AppID.Replace("'", "''")
|
||||
Log "Neues Teams gefunden (AUMID: $($startApp.AppID)) - wird fuer den verzoegerten Start verwendet."
|
||||
$launcherBody = @"
|
||||
# Automatisch erzeugt von Remediate-TeamsAutostart.ps1 - nicht manuell bearbeiten,
|
||||
# wird bei jedem Remediation-Lauf ueberschrieben.
|
||||
Start-Sleep -Seconds $delaySeconds
|
||||
Start-Process -FilePath 'explorer.exe' -ArgumentList 'shell:appsFolder\$aumidEscaped'
|
||||
"@
|
||||
} else {
|
||||
$exeEscaped = $classicExe.Replace("'", "''")
|
||||
Log "Klassisches Teams gefunden - wird fuer den verzoegerten Start verwendet: $classicExe"
|
||||
$launcherBody = @"
|
||||
# Automatisch erzeugt von Remediate-TeamsAutostart.ps1 - nicht manuell bearbeiten,
|
||||
# wird bei jedem Remediation-Lauf ueberschrieben.
|
||||
Start-Sleep -Seconds $delaySeconds
|
||||
Start-Process -FilePath '$exeEscaped'
|
||||
"@
|
||||
}
|
||||
|
||||
try {
|
||||
Set-Content -Path $LauncherPath -Value $launcherBody -Encoding UTF8 -Force
|
||||
} catch {
|
||||
Log "FEHLER beim Schreiben des Launcher-Skripts '$LauncherPath': $_"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# --- 5b) Versteckte .lnk-Verknuepfung im Autostart-Ordner erzeugen ---------
|
||||
# Erzeugt hier nur die Verknuepfungsdatei per COM-Automation (WScript.Shell) -
|
||||
# das laeuft NUR jetzt, waehrend der Remediation, und startet KEIN wscript.exe
|
||||
# bei der Anmeldung. Bei jeder Anmeldung fuehrt Windows lediglich die
|
||||
# Verknuepfung aus, die powershell.exe mit dem Launcher-Skript aufruft.
|
||||
$startupFolder = $startupFolders[0]
|
||||
if (-not (Test-Path $startupFolder)) {
|
||||
New-Item -Path $startupFolder -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
$lnkPath = Join-Path $startupFolder $LnkFileName
|
||||
$powershellExe = Join-Path $env:SystemRoot "System32\WindowsPowerShell\v1.0\powershell.exe"
|
||||
|
||||
try {
|
||||
$wshell = New-Object -ComObject WScript.Shell
|
||||
$shortcut = $wshell.CreateShortcut($lnkPath)
|
||||
$shortcut.TargetPath = $powershellExe
|
||||
$shortcut.Arguments = "-NoLogo -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$LauncherPath`""
|
||||
$shortcut.WindowStyle = 7 # Minimiert (zusaetzliche Absicherung neben -WindowStyle Hidden)
|
||||
$shortcut.Description = "Startet Microsoft Teams verzoegert nach der Anmeldung"
|
||||
$shortcut.Save()
|
||||
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($wshell) | Out-Null
|
||||
|
||||
if (Test-Path $lnkPath) {
|
||||
Log "Verzoegerter Start eingerichtet: '$lnkPath' -> '$LauncherPath' (Teams startet $DelayMinutes Minute(n) nach Anmeldung, versteckt)."
|
||||
} else {
|
||||
Log "FEHLER: '$lnkPath' konnte nicht angelegt werden."
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Log "FEHLER beim Erstellen der Verknuepfung '$lnkPath': $_"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Log "=== Remediation abgeschlossen ==="
|
||||
exit 0
|
||||
@@ -0,0 +1,43 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
EINMAL-KORREKTUR fuer Rechner, auf denen die fehlerhafte erste Version von
|
||||
Remediate-TeamsAutostart.ps1 bereits gelaufen ist. Diese Version hatte
|
||||
faelschlicherweise ALLE Unterschluessel unter
|
||||
HKCU:\...\AppModel\SystemAppData\MSTeams_8wekyb3d8bbwe auf State=0
|
||||
(deaktiviert) gesetzt - nicht nur den echten Autostart-Eintrag
|
||||
"TeamsTfwStartupTask".
|
||||
|
||||
Dieses Skript setzt die faelschlich deaktivierten App-Erweiterungen
|
||||
zurueck auf ihren normalen Wert (State=2 = Enabled) und laesst
|
||||
"TeamsTfwStartupTask" bewusst auf 0 (Autostart bleibt deaktiviert).
|
||||
|
||||
.NOTES
|
||||
Einmalig pro betroffenem Nutzerprofil ausfuehren (im Nutzerkontext, HKCU).
|
||||
#>
|
||||
|
||||
$base = "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData\MSTeams_8wekyb3d8bbwe"
|
||||
|
||||
# Nur diese wurden faelschlicherweise angefasst - TeamsTfwStartupTask bewusst NICHT hier drin
|
||||
$keysToRestore = @("AppUriHandlers", "HAM", "PSR", "Schemas", "SplashScreen")
|
||||
|
||||
if (-not (Test-Path $base)) {
|
||||
Write-Output "Kein neues Teams unter diesem Profil gefunden - nichts zu tun."
|
||||
exit 0
|
||||
}
|
||||
|
||||
foreach ($name in $keysToRestore) {
|
||||
$path = Join-Path $base $name
|
||||
if (Test-Path $path) {
|
||||
Set-ItemProperty -Path $path -Name "State" -Value 2 -Type DWord
|
||||
Write-Output "Wiederhergestellt: $name -> State=2 (Enabled)"
|
||||
} else {
|
||||
Write-Output "Uebersprungen (nicht vorhanden): $name"
|
||||
}
|
||||
}
|
||||
|
||||
$startupPath = Join-Path $base "TeamsTfwStartupTask"
|
||||
if (Test-Path $startupPath) {
|
||||
Write-Output "Unveraendert (bewusst deaktiviert): TeamsTfwStartupTask bleibt auf State=0."
|
||||
}
|
||||
|
||||
Write-Output "Fertig."
|
||||
Reference in new issue
Block a user