# -- Update Environment Variables For Current User -- # function Update-UserVars { $ConsoleUser = ([Security.Principal.WindowsIdentity]::GetCurrent().Name.Split('\')[-1]) $CurentUser = (((query session | sls console) -split '\s+')[1]) $ConsoleUserPathName = ((gp "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$((New-Object Security.Principal.NTAccount($ConsoleUser)).Translate([Security.Principal.SecurityIdentifier]).Value)").ProfileImagePath).Split('\', 2)[1] $CurentUserPathName = ((gp "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$((New-Object Security.Principal.NTAccount($CurentUser)).Translate([Security.Principal.SecurityIdentifier]).Value)").ProfileImagePath).Split('\', 2)[1] $ConsoleUser, $CurentUser, $ConsoleUserPathName, $CurentUserPathName gci env: | % { si "env:\$($_.Name)" ($_.Value -replace [regex]::Escape($ConsoleUserPathName), $CurentUserPathName -replace [regex]::Escape($ConsoleUser), $CurentUser) } }; Update-UserVars # Список ключевых слов (регулярное выражение) $pattern = "Zoom|JW|OBS" Write-Host "Поиск задач, содержащих: $pattern" -ForegroundColor Cyan # Получаем все задачи и фильтруем (используем @(), чтобы всегда был массив) $tasksToDelete = @(Get-ScheduledTask | Where-Object { $_.TaskName -match $pattern -or $_.TaskPath -match $pattern }) if ($tasksToDelete.Count -gt 0) { Write-Host "Найдено задач: $($tasksToDelete.Count)" -ForegroundColor Green foreach ($task in $tasksToDelete) { try { Write-Host "Удаление: $($task.TaskName) (Путь: $($task.TaskPath))" -ForegroundColor Yellow # Удаляем задачу. -Confirm:$false подавляет запрос подтверждения. Unregister-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -Confirm:$false } catch { Write-Host "Ошибка при удалении $($task.TaskName): $($_.Exception.Message)" -ForegroundColor Red } } Write-Host "`nОчистка завершена." -ForegroundColor Green } else { Write-Host "Задачи, содержащие эти слова, не обнаружены." -ForegroundColor Gray Write-Host "Совет: Убедитесь, что вы запустили PowerShell от имени Администратора." -ForegroundColor DarkYellow }