pawelkl

cleanpc

Aug 14th, 2025 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Ścieżka do folderu z profilami użytkowników
  2. $profilesPath = "C:\Users"
  3. # Ścieżka do folderu "Pulpit" dla wszystkich użytkowników
  4. $commonDesktopPath = "C:\Users\Public\Desktop"
  5.  
  6. # Pobierz wszystkie profile użytkowników
  7. $profiles = Get-ChildItem -Path $profilesPath
  8.  
  9. # Lista nazw programów, których skróty nie będą usuwane
  10. $excludedShortcuts = @("Visual Studio Code", "Code::Blocks", "GIMP", "JetBrains")
  11.  
  12. foreach ($profile in $profiles) {
  13.     # Sprawdź, czy nazwa profilu zawiera "uczeń"
  14.     if ($profile.Name -like "*uczeń*") {
  15.         # Ścieżki do folderów
  16.         $documentsPath = Join-Path -Path $profile.FullName -ChildPath "Documents"
  17.         $desktopPath = Join-Path -Path $profile.FullName -ChildPath "Desktop"
  18.         $downloadsPath = Join-Path -Path $profile.FullName -ChildPath "Downloads"
  19.  
  20.         # Usuń wszystkie pliki z folderu Dokumenty
  21.         if (Test-Path $documentsPath) {
  22.             Remove-Item -Path "$documentsPath\*" -Recurse -Force -ErrorAction SilentlyContinue
  23.         }
  24.  
  25.         # Usuń pliki z folderu Pulpit, z wyjątkiem skrótów do wykluczonych programów
  26.         if (Test-Path $desktopPath) {
  27.             $desktopItems = Get-ChildItem -Path $desktopPath
  28.             foreach ($item in $desktopItems) {
  29.                 if ($item.PSIsContainer -or ($item.Extension -ne ".lnk")) {
  30.                     # Jeśli to nie jest skrót, usuń
  31.                     Remove-Item -Path $item.FullName -Recurse -Force -ErrorAction SilentlyContinue
  32.                 } else {
  33.                     # Sprawdź, czy skrót nie jest jednym z wykluczonych
  34.                     $shortcutTarget = (Get-Item $item.FullName).Target
  35.                     if ($excludedShortcuts -notcontains $shortcutTarget) {
  36.                         Remove-Item -Path $item.FullName -Force -ErrorAction SilentlyContinue
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.  
  42.         # Usuń wszystkie pliki z folderu Pobrane
  43.         if (Test-Path $downloadsPath) {
  44.             Remove-Item -Path "$downloadsPath\*" -Recurse -Force -ErrorAction SilentlyContinue
  45.         }
  46.     }
  47. }
  48.  
  49. # Usuń skrót do Uniget z folderu "Pulpit" dla wszystkich użytkowników
  50. if (Test-Path $commonDesktopPath) {
  51.     $unigetShortcut = Join-Path -Path $commonDesktopPath -ChildPath "UnigetUI.lnk"
  52.     if (Test-Path $unigetShortcut) {
  53.         Remove-Item -Path $unigetShortcut -Force -ErrorAction SilentlyContinue
  54.     }
  55. }
  56.  
  57. # Opróżnij kosz
  58. $Shell = New-Object -ComObject Shell.Application
  59. $RecycleBin = $Shell.Namespace(10)
  60. $RecycleBin.Items() | ForEach-Object { $_.InvokeVerb('delete') }
  61.  
Add Comment
Please, Sign In to add comment