commit 060dfad252ffebb4034baa41a9fe60046acb7f47 Author: Krzysztof Smaga Date: Tue Jul 21 13:30:02 2026 +0200 Upload files to "/" diff --git a/ChangeComputerName.ps1 b/ChangeComputerName.ps1 new file mode 100644 index 0000000..37619af --- /dev/null +++ b/ChangeComputerName.ps1 @@ -0,0 +1,29 @@ +# ChangeComputerName.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +# Pobieranie danych od użytkownika +$compNumber = Read-Host "Numer komputera" +$roomNumber = Read-Host "Sala" + +# Budowanie nowej nazwy komputera +$newName = "TE-LOD-D-${compNumber}s${roomNumber}" + +Write-Host "" # Pusta linia dla lepszej czytelności + +try { + # Zmiana nazwy komputera + Rename-Computer -NewName $newName -ErrorAction Stop + + # Wyświetlanie komunikatów o sukcesie + Write-Host "[Info] Ustawiono nazwę komputera na $newName" -ForegroundColor Green + Write-Host "[Info] Automatyczny restart nastąpi za chwile..." -ForegroundColor Yellow + + # Czekamy 4 sekundy, żeby użytkownik przeczytał komunikat + Start-Sleep -Seconds 4 + + # Wymuszenie restartu + Restart-Computer -Force +} catch { + Write-Host "[Błąd] Nie udało się zmienić nazwy. Szczegóły: $_" -ForegroundColor Red +} \ No newline at end of file diff --git a/CleanINF03Session.ps1 b/CleanINF03Session.ps1 new file mode 100644 index 0000000..6ccfdb8 --- /dev/null +++ b/CleanINF03Session.ps1 @@ -0,0 +1,77 @@ +# CleanINF03Session.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +$inf03Path = "C:\Users\inf03" +$xamppHtdocs = "C:\xampp\htdocs" +$mysqlData = "C:\xampp\mysql\data" +$mysqlBackup = "C:\xampp\mysql\backup" + +Write-Host "Rozpoczynam sprzątanie stanowiska (profil: inf03)..." -ForegroundColor Cyan +Write-Host "----------------------------------------------------" + +# 1. Zatrzymanie usług XAMPP +Write-Host "[1/6] Zatrzymywanie usług Apache i MySQL..." -NoNewline +try { + # Domyślne nazwy usług w XAMPP to 'Apache2.4' oraz 'mysql' + Stop-Service -Name "Apache2.4", "mysql" -Force -ErrorAction SilentlyContinue + Write-Host " GOTOWE" -ForegroundColor Green +} catch { + Write-Host " POMINIĘTO (usługi mogą być wyłączone)" -ForegroundColor Yellow +} + +# Czekamy 2 sekundy, aby upewnić się, że usługi puściły blokady na plikach bazy danych +Start-Sleep -Seconds 2 + +# 2. Czyszczenie htdocs +Write-Host "[2/6] Czyszczenie folderu htdocs..." -NoNewline +if (Test-Path $xamppHtdocs) { + Remove-Item -Path "$xamppHtdocs\*" -Recurse -Force -ErrorAction SilentlyContinue + Write-Host " GOTOWE" -ForegroundColor Green +} else { + Write-Host " BRAK FOLDERU" -ForegroundColor Yellow +} + +# 3. Czyszczenie Obrazów i Dokumentów +Write-Host "[3/6] Usuwanie danych z folderów Obrazy i Dokumenty..." -NoNewline +$docsPath = "$inf03Path\Documents" +$picsPath = "$inf03Path\Pictures" + +if (Test-Path $docsPath) { Remove-Item -Path "$docsPath\*" -Recurse -Force -ErrorAction SilentlyContinue } +if (Test-Path $picsPath) { Remove-Item -Path "$picsPath\*" -Recurse -Force -ErrorAction SilentlyContinue } +Write-Host " GOTOWE" -ForegroundColor Green + +# 4. Resetowanie bazy danych MySQL do stanu czystego +Write-Host "[4/6] Przywracanie czystej bazy danych MySQL..." -NoNewline +if ((Test-Path $mysqlData) -and (Test-Path $mysqlBackup)) { + # Usuwamy zmienioną bazę + Remove-Item -Path "$mysqlData\*" -Recurse -Force -ErrorAction SilentlyContinue + # Kopiujemy świeże pliki z backupu + Copy-Item -Path "$mysqlBackup\*" -Destination $mysqlData -Recurse -Force + Write-Host " GOTOWE" -ForegroundColor Green +} else { + Write-Host " BŁĄD (Brak folderu data lub backup w C:\xampp\mysql\)" -ForegroundColor Red +} + +# 5. Uruchomienie usług +Write-Host "[5/6] Uruchamianie usług Apache i MySQL..." -NoNewline +try { + Start-Service -Name "Apache2.4", "mysql" -ErrorAction Stop + Write-Host " GOTOWE" -ForegroundColor Green +} catch { + Write-Host " BŁĄD (Sprawdź w panelu XAMPP)" -ForegroundColor Red +} + +# 6. Usuwanie KATALOGÓW z pulpitu +Write-Host "[6/6] Usuwanie projektów (katalogów) z Pulpitu..." -NoNewline +$desktopPath = "$inf03Path\Desktop" +if (Test-Path $desktopPath) { + # Get-ChildItem -Directory gwarantuje, że skasujemy tylko foldery, oszczędzając skróty (.lnk) + Get-ChildItem -Path $desktopPath -Directory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue + Write-Host " GOTOWE" -ForegroundColor Green +} else { + Write-Host " BRAK PULPITU" -ForegroundColor Yellow +} + +Write-Host "----------------------------------------------------" +Write-Host "Stanowisko przygotowane do kolejnego egzaminu!" -ForegroundColor Cyan \ No newline at end of file diff --git a/CleanINF04Session.ps1 b/CleanINF04Session.ps1 new file mode 100644 index 0000000..2a332d2 --- /dev/null +++ b/CleanINF04Session.ps1 @@ -0,0 +1,39 @@ +# CleanINF04Session.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +$inf04Path = "C:\Users\inf04" +$desktopPath = "$inf04Path\Desktop" +$zipPath = "C:\scripts\inf04\pulpit.zip" + +Write-Host "Rozpoczynam sprzątanie stanowiska (profil: inf04)..." -ForegroundColor Cyan +Write-Host "----------------------------------------------------" + +# 1. Usuwanie starych katalogów z pulpitu +Write-Host "[1/2] Usuwanie starych projektów (katalogów) z Pulpitu..." -NoNewline +if (Test-Path $desktopPath) { + # Przełącznik -Directory gwarantuje, że usuniemy tylko foldery, zostawiając skróty systemowe + Get-ChildItem -Path $desktopPath -Directory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue + Write-Host " GOTOWE" -ForegroundColor Green +} else { + Write-Host " BRAK PULPITU" -ForegroundColor Yellow +} + +# 2. Wypakowywanie archiwum z projektami startowymi +Write-Host "[2/2] Wypakowywanie projektów startowych z pulpit.zip..." -NoNewline +if (Test-Path $zipPath) { + try { + # Expand-Archive wypakowuje zawartość ZIPa we wskazane miejsce. + # Używamy -Force, aby nadpisać ewentualne pliki o tej samej nazwie. + Expand-Archive -Path $zipPath -DestinationPath $desktopPath -Force -ErrorAction Stop + Write-Host " GOTOWE" -ForegroundColor Green + } catch { + Write-Host " BŁĄD" -ForegroundColor Red + Write-Host " Szczegóły: $_" -ForegroundColor Red + } +} else { + Write-Host " BRAK PLIKU (Nie znaleziono archiwum w: $zipPath)" -ForegroundColor Red +} + +Write-Host "----------------------------------------------------" +Write-Host "Stanowisko przygotowane do kolejnego egzaminu!" -ForegroundColor Cyan \ No newline at end of file diff --git a/CleanUserProfiles.ps1 b/CleanUserProfiles.ps1 new file mode 100644 index 0000000..2948975 --- /dev/null +++ b/CleanUserProfiles.ps1 @@ -0,0 +1,66 @@ +# CleanUserProfiles.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +# 1. Lista SID-ów systemowych do wykluczenia +$ExcludedSIDs = @( + "S-1-5-21-3670944717-3182157424-105470765-500", # Główny Administrator + "S-1-5-18", # Local System + "S-1-5-19", # Local Service + "S-1-5-20" # Network Service +) + +# 2. Lista kont egzaminacyjnych i pracownianych do wykluczenia +$ExcludedAccounts = @( + "inf03", + "inf04", + "teoria", + "aud" +) + +Write-Host "Rozpoczynam skanowanie i czyszczenie profili użytkowników..." -ForegroundColor Cyan +Write-Host "" + +# Pobieramy profile, pomijając systemowe wbudowane (np. folder Default) +$profiles = Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.Special -eq $false } + +$deletedCount = 0 + +foreach ($profile in $profiles) { + $sid = $profile.SID + $path = $profile.LocalPath + $folderName = Split-Path $path -Leaf + + # Próba przetłumaczenia numeru SID na przyjazną nazwę konta + $accountName = "" + try { + $sidObj = [System.Security.Principal.SecurityIdentifier]::new($sid) + $ntAccount = $sidObj.Translate([System.Security.Principal.NTAccount]) + # Wynik to np. DOMENA\inf03 lub NAZWAKOMPUTERA\inf03, więc odcinamy przedrostek + $accountName = $ntAccount.Value.Split('\')[-1] + } catch { + # Jeśli konto domenowe zostało usunięte z AD i nie da się go przetłumaczyć + $accountName = $folderName + } + + # Sprawdzamy, czy SID, nazwa konta lub nazwa folderu znajdują się na listach wykluczeń + if ($sid -in $ExcludedSIDs -or $accountName -in $ExcludedAccounts -or $folderName -in $ExcludedAccounts) { + Write-Host "[Pominięto] $path (Konto na liście wykluczeń)" -ForegroundColor DarkGray + continue + } + + Write-Host "[Info] Próba usunięcia: $path (SID: $sid)..." -NoNewline + + try { + Remove-CimInstance -InputObject $profile -ErrorAction Stop + Write-Host " SUKCES" -ForegroundColor Green + $deletedCount++ + } catch { + Write-Host " BŁĄD" -ForegroundColor Red + Write-Host " Szczegóły: $_" -ForegroundColor Red + Write-Host " (Profil może być w użyciu.)" -ForegroundColor Yellow + } +} + +Write-Host "" +Write-Host "[Podsumowanie] Usunięto profili: $deletedCount" -ForegroundColor Cyan \ No newline at end of file diff --git a/DisableVHDExpand.ps1 b/DisableVHDExpand.ps1 new file mode 100644 index 0000000..cbf7d81 --- /dev/null +++ b/DisableVHDExpand.ps1 @@ -0,0 +1,22 @@ +# DisableVHDExpand.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +Write-Host "Konfiguracja dysków VHD..." -ForegroundColor Cyan + +$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\FsDepends\Parameters" + +# Upewniamy się, że klucz Parameters istnieje (domyślnie powinien, ale lepiej sprawdzić) +if (-not (Test-Path $regPath)) { + New-Item -Path $regPath -Force | Out-Null +} + +try { + # Wartość 4 oznacza wyłączenie rozszerzania VHD przy rozruchu + Set-ItemProperty -Path $regPath -Name "VirtualDiskExpandOnMount" -Value 4 -Type DWord + + Write-Host "[SUKCES] Ustawiono VirtualDiskExpandOnMount na wartość 4." -ForegroundColor Green + Write-Host " Dynamiczne dyski VHD nie będą już sztucznie puchnąć przy starcie." -ForegroundColor Green +} catch { + Write-Host "[BŁĄD] Nie udało się zmodyfikować rejestru. Szczegóły: $_" -ForegroundColor Red +} \ No newline at end of file diff --git a/FinalizeSetup.ps1 b/FinalizeSetup.ps1 new file mode 100644 index 0000000..f4d6ff5 --- /dev/null +++ b/FinalizeSetup.ps1 @@ -0,0 +1,132 @@ +# FinalizeSetup.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +Write-Host "==========================================" -ForegroundColor Cyan +Write-Host " KREATOR FINALIZACJI KONFIGURACJI" -ForegroundColor Cyan +Write-Host "==========================================" -ForegroundColor Cyan +Write-Host "" + +# --------------------------------------------------------- +# 1. Ukrywanie dysków (Modyfikacja Rejestru - NoDrives) +# --------------------------------------------------------- +$drivesToHide = Read-Host "Jakie dyski ukryć? (np. E F G, wciśnij Enter by pominąć)" + +if (![string]::IsNullOrWhiteSpace($drivesToHide)) { + # Rozdzielamy ciąg po spacjach i wyliczamy maskę bitową + $letters = $drivesToHide -split '\s+' + $noDrivesValue = 0 + + foreach ($letter in $letters) { + $char = $letter.ToUpper()[0] + # Sprawdzamy, czy to litera od A do Z + if ($char -ge 65 -and $char -le 90) { + # Wzór: A=1, B=2, C=4, D=8, E=16 itd. + $bit = [math]::Pow(2, ([int]$char - 65)) + $noDrivesValue += $bit + } + } + + $regPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" + if (!(Test-Path $regPath)) { + New-Item -Path $regPath -Force | Out-Null + } + + Set-ItemProperty -Path $regPath -Name "NoDrives" -Value $noDrivesValue -Type DWord + Write-Host "[INFO] Ustawiono ukrywanie dysków (Wartość w rejestrze: $noDrivesValue)." -ForegroundColor Green +} else { + Write-Host "[INFO] Pominięto ukrywanie dysków." -ForegroundColor DarkGray +} + +Write-Host "" + +# --------------------------------------------------------- +# 2. Dodawanie dysku na pulpit publiczny +# --------------------------------------------------------- +$shortcutDrive = Read-Host "Jaki dysk dodać na Pulpit publiczny? (np. E, wciśnij Enter by pominąć)" + +if (![string]::IsNullOrWhiteSpace($shortcutDrive)) { + $shortcutDriveLetter = $shortcutDrive.ToUpper()[0] + $shortcutName = Read-Host "Jak nazwać ten skrót na pulpicie?" + + # Pobieranie ścieżki do folderu "Pulpit publiczny" (C:\Users\Public\Desktop) + $publicDesktop = [Environment]::GetFolderPath('CommonDesktopDirectory') + $shortcutPath = Join-Path -Path $publicDesktop -ChildPath "$shortcutName.lnk" + + # Wykorzystanie obiektu COM do utworzenia skrótu + $wshShell = New-Object -ComObject WScript.Shell + $shortcut = $wshShell.CreateShortcut($shortcutPath) + $shortcut.TargetPath = "$shortcutDriveLetter`:\" + $shortcut.Save() + + Write-Host "[INFO] Utworzono publiczny skrót '$shortcutName' kierujący na $shortcutDriveLetter:\." -ForegroundColor Green +} else { + Write-Host "[INFO] Pominięto tworzenie skrótu." -ForegroundColor DarkGray +} + +Write-Host "" + +# --------------------------------------------------------- +# 3. Połączenie z Wi-Fi (Tworzenie i import profilu XML) +# --------------------------------------------------------- +$connectWifi = Read-Host "Połączyć do Wi-Fi? (T/n)" + +if ($connectWifi -match '^[Tt]$') { + $ssid = Read-Host "Podaj nazwę Wi-Fi" + $password = Read-Host "Podaj hasło do Wi-Fi" + + # PowerShell wymaga utworzenia pliku XML, aby dodać sieć z hasłem bez GUI + $xmlProfile = @" + + + $ssid + + + $ssid + + + ESS + auto + + + + WPA2PSK + AES + false + + + passPhrase + false + $password + + + + +"@ + + $tempXmlPath = Join-Path $env:TEMP "$ssid-profile.xml" + $xmlProfile | Out-File -FilePath $tempXmlPath -Encoding UTF8 + + Write-Host "[INFO] Dodawanie profilu sieci $ssid do systemu..." -NoNewline + $addResult = netsh wlan add profile filename="$tempXmlPath" + + # Sprzątanie - usuwamy plik XML z jawnym hasłem + Remove-Item -Path $tempXmlPath -Force + + if ($addResult -match "is added" -or $addResult -match "został dodany") { + Write-Host " GOTOWE" -ForegroundColor Green + Write-Host "[INFO] Próba połączenia z siecią $ssid..." -ForegroundColor Cyan + netsh wlan connect name="$ssid" + } else { + Write-Host " BŁĄD" -ForegroundColor Red + Write-Host " Odpowiedź systemu: $addResult" -ForegroundColor Yellow + } +} else { + Write-Host "[INFO] Pominięto konfigurację Wi-Fi." -ForegroundColor DarkGray +} + +Write-Host "" +Write-Host "==========================================" -ForegroundColor Cyan +Write-Host " Konfiguracja zakończona!" -ForegroundColor Cyan +Write-Host "==========================================" -ForegroundColor Cyan +Write-Host "UWAGA: Ukrycie dysków zacznie działać po restarcie komputera (lub ponownym uruchomieniu procesu explorer.exe)." -ForegroundColor Yellow \ No newline at end of file diff --git a/JoinToDomain.ps1 b/JoinToDomain.ps1 new file mode 100644 index 0000000..1e23de1 --- /dev/null +++ b/JoinToDomain.ps1 @@ -0,0 +1 @@ +Start-Process "ms-settings:workplace" \ No newline at end of file diff --git a/OptimizeVHD.ps1 b/OptimizeVHD.ps1 new file mode 100644 index 0000000..0caa7a2 --- /dev/null +++ b/OptimizeVHD.ps1 @@ -0,0 +1,39 @@ +# OptimizeVHD.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +Write-Host "Optymalizacja systemu pod obraz VHD / Snapshoty..." -ForegroundColor Cyan + +# 1. Wyłączenie Hibernacji i Szybkiego Uruchamiania (Fast Startup) +# To usunie plik hiberfil.sys, który potrafi zajmować tyle GB, ile masz RAMu +Write-Host "[1/2] Wyłączanie hibernacji (hiberfil.sys)..." -NoNewline +try { + # Najczystsza metoda zalecana przez Microsoft to powercfg, która sama modyfikuje rejestr + # w kluczu HKLM\System\CurrentControlSet\Control\Power (wartość HibernateEnabled) + Start-Process -FilePath "powercfg.exe" -ArgumentList "/hibernate off" -Wait -NoNewWindow + Write-Host " GOTOWE" -ForegroundColor Green +} catch { + Write-Host " BŁĄD" -ForegroundColor Red +} + +# 2. Ustawienie stałego rozmiaru pliku stronicowania (Pagefile) +# Zapobiega nagłemu puchnięciu VHD przy braku pamięci RAM +Write-Host "[2/2] Ustawianie stałego rozmiaru pliku stronicowania (2048 MB)..." -NoNewline +try { + # Wyłączenie automatycznego zarządzania plikiem stronicowania w rejestrze + $regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" + Set-ItemProperty -Path $regPath -Name "AutomaticManagedPagefile" -Value 0 -Type DWord + + # Ustawienie stałego rozmiaru (np. Min 2048 MB, Max 2048 MB) + # Jeśli chcesz mniejszy lub większy, zmień wartości "2048 2048" poniżej + Set-ItemProperty -Path $regPath -Name "PagingFiles" -Value "C:\pagefile.sys 2048 2048" -Type MultiString + + Write-Host " GOTOWE" -ForegroundColor Green +} catch { + Write-Host " BŁĄD" -ForegroundColor Red + Write-Host " Szczegóły: $_" -ForegroundColor Red +} + +Write-Host "" +Write-Host "==========================================" -ForegroundColor Cyan +Write-Host "UWAGA: Zmiany w pliku stronicowania będą aktywne po ponownym uruchomieniu komputera." -ForegroundColor Yellow \ No newline at end of file diff --git a/RestartComputer.ps1 b/RestartComputer.ps1 new file mode 100644 index 0000000..ba99879 --- /dev/null +++ b/RestartComputer.ps1 @@ -0,0 +1,18 @@ +# RestartComputer.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +param ( + [Parameter(Position=0, HelpMessage="Czas do restartu w sekundach (domyślnie 5)")] + [int]$Delay = 5 +) + +if ($Delay -gt 0) { + Write-Host "[INFO] Zlecono restart za $Delay sekund..." -ForegroundColor Yellow + # Używamy systemowego shutdown.exe, ponieważ automatycznie wyświetla on + # na środku ekranu ucznia duży, niebieski komunikat o nadchodzącym restarcie + shutdown.exe /r /t $Delay /c "Komputer zostanie zrestartowany przez instruktora." /f +} else { + Write-Host "[INFO] Wymuszam natychmiastowy restart komputera (bez ostrzeżenia)..." -ForegroundColor Red + Restart-Computer -Force +} \ No newline at end of file diff --git a/SetAutoChrome.ps1 b/SetAutoChrome.ps1 new file mode 100644 index 0000000..91a91c5 --- /dev/null +++ b/SetAutoChrome.ps1 @@ -0,0 +1,51 @@ +# SetAutoChrome.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +param ( + [Parameter(Mandatory=$true, Position=0, HelpMessage="Podaj adres URL")] + [string]$Url, + + [Parameter(Mandatory=$true, Position=1, HelpMessage="Podaj nazwę konta użytkownika")] + [string]$UserName +) + +# Budowanie ścieżki do folderu Autostart wybranego użytkownika +$startupFolder = "C:\Users\$UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" + +if (-not (Test-Path $startupFolder)) { + Write-Host "[BŁĄD] Nie znaleziono folderu Autostart dla '$UserName'." -ForegroundColor Red + Write-Host " Upewnij się, że użytkownik istnieje i zalogował się przynajmniej raz, aby system utworzył mu profil." -ForegroundColor Yellow + Exit +} + +# Szukanie pliku wykonywalnego Chrome +$chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe" +if (-not (Test-Path $chromePath)) { + $chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" + if (-not (Test-Path $chromePath)) { + Write-Host "[BŁĄD] Nie można zlokalizować przeglądarki Google Chrome w domyślnych ścieżkach." -ForegroundColor Red + Exit + } +} + +$shortcutPath = Join-Path -Path $startupFolder -ChildPath "AutoChrome.lnk" + +try { + # Tworzenie skrótu za pomocą obiektu COM + $wshShell = New-Object -ComObject WScript.Shell + $shortcut = $wshShell.CreateShortcut($shortcutPath) + + $shortcut.TargetPath = $chromePath + # Podajemy argumenty: przełącznik do maksymalizacji + adres w cudzysłowach + $shortcut.Arguments = "--start-maximized `"$Url`"" + # Wymuszenie uruchomienia zmaksymalizowanego okna z poziomu systemu (3 = Maximized) + $shortcut.WindowStyle = 3 + + $shortcut.Save() + + Write-Host "[SUKCES] Dodano Chrome do autostartu dla użytkownika: $UserName" -ForegroundColor Green + Write-Host " Adres startowy: $Url" -ForegroundColor Cyan +} catch { + Write-Host "[BŁĄD] Nie udało się utworzyć skrótu. Szczegóły: $_" -ForegroundColor Red +} \ No newline at end of file diff --git a/SetupSSH.ps1 b/SetupSSH.ps1 new file mode 100644 index 0000000..c268c21 --- /dev/null +++ b/SetupSSH.ps1 @@ -0,0 +1,78 @@ +# SetupSSH.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +Write-Host "Konfiguracja serwera OpenSSH..." -ForegroundColor Cyan + +# 1. Sprawdzanie i instalacja OpenSSH Server +$sshStatus = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' +if ($sshStatus.State -ne 'Installed') { + Write-Host "[1/5] Instalowanie składnika OpenSSH Server (to może chwilę potrwać)..." -NoNewline + Add-WindowsCapability -Online -Name $sshStatus.Name | Out-Null + Write-Host " GOTOWE" -ForegroundColor Green +} else { + Write-Host "[1/5] OpenSSH Server jest już zainstalowany." -ForegroundColor Green +} + +# 2. Ustawienie usługi na automatyczny start +Write-Host "[2/5] Konfiguracja usługi sshd..." -NoNewline +Set-Service -Name sshd -StartupType Automatic +Start-Service sshd +Write-Host " GOTOWE" -ForegroundColor Green + +# 3. Reguła zapory +Write-Host "[3/5] Weryfikacja reguły zapory dla portu 22..." -NoNewline +if (-not (Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) { + New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null +} +Write-Host " GOTOWE" -ForegroundColor Green + +# 4. Magia konfiguracji (Ominięcie problemu grupy Administrators) +Write-Host "[4/5] Optymalizacja pliku sshd_config..." -NoNewline +$sshdConfigPath = "$env:ProgramData\ssh\sshd_config" +if (Test-Path $sshdConfigPath) { + $content = Get-Content $sshdConfigPath + + # Komentujemy linie, które zmuszają Administratorów do używania globalnego pliku kluczy. + # Dzięki temu logowanie działa standardowo z folderu C:\Users\Konto\.ssh + $content = $content -replace '(?m)^Match Group administrators','#Match Group administrators' + $content = $content -replace '(?m)^\s*AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys','# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys' + + $content | Set-Content $sshdConfigPath -Encoding UTF8 + Restart-Service sshd + Write-Host " GOTOWE" -ForegroundColor Green +} else { + Write-Host " BŁĄD (Brak pliku konfiguracji)" -ForegroundColor Red +} + +# 5. Dodawanie Twojego klucza publicznego +Write-Host "" +Write-Host "[5/5] Konfiguracja logowania bez hasła" -ForegroundColor Cyan +$pubKey = Read-Host "Wklej swój klucz publiczny SSH (zaczyna się np. od ssh-rsa..., wciśnij Enter by pominąć)" + +if (![string]::IsNullOrWhiteSpace($pubKey)) { + $targetUser = Read-Host "Dla jakiego lokalnego użytkownika chcesz dodać ten klucz? (np. Administrator, inf03)" + + # Tworzenie folderu .ssh + $sshFolder = "C:\Users\$targetUser\.ssh" + if (-not (Test-Path $sshFolder)) { + New-Item -Path $sshFolder -ItemType Directory -Force | Out-Null + } + + # Zapis klucza + $authKeysFile = "$sshFolder\authorized_keys" + + # Sprawdzenie czy klucz już istnieje w pliku, żeby go nie dublować + if ((Test-Path $authKeysFile) -and (Get-Content $authKeysFile) -match [regex]::Escape($pubKey)) { + Write-Host "[INFO] Ten klucz znajduje się już w pliku authorized_keys dla $targetUser." -ForegroundColor Yellow + } else { + Add-Content -Path $authKeysFile -Value $pubKey -Encoding UTF8 + Write-Host "[SUKCES] Dodano klucz dla użytkownika $targetUser!" -ForegroundColor Green + Write-Host " Możesz logować się z maszyny z kluczem prywatnym: ssh $targetUser@" -ForegroundColor Yellow + } +} else { + Write-Host "[INFO] Pominięto dodawanie klucza." -ForegroundColor DarkGray +} + +Write-Host "" +Write-Host "Gotowe! Serwer SSH działa i nasłuchuje w tle." -ForegroundColor Cyan \ No newline at end of file diff --git a/ShowComputerInfo.ps1 b/ShowComputerInfo.ps1 new file mode 100644 index 0000000..91b8dd0 --- /dev/null +++ b/ShowComputerInfo.ps1 @@ -0,0 +1,41 @@ +# ShowComputerInfo.ps1 + +Write-Host "==========================================" -ForegroundColor Cyan +Write-Host " RAPORT O STANIE KOMPUTERA" -ForegroundColor Cyan +Write-Host "==========================================" -ForegroundColor Cyan + +# 1. Zużycie miejsca na dysku C: +$diskC = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='C:'" +$totalDiskGb = [math]::Round($diskC.Size / 1GB, 2) +$freeDiskGb = [math]::Round($diskC.FreeSpace / 1GB, 2) +$usedDiskGb = $totalDiskGb - $freeDiskGb +$diskPercent = [math]::Round(($usedDiskGb / $totalDiskGb) * 100, 1) + +$diskColor = if ($diskPercent -ge 90) { "Red" } elseif ($diskPercent -ge 75) { "Yellow" } else { "Green" } +Write-Host "Dysk C: " -NoNewline +Write-Host "$usedDiskGb GB zajęte z $totalDiskGb GB ($diskPercent%)" -ForegroundColor $diskColor + +# 2. Liczba zalogowanych użytkowników (interaktywnych) +$loggedUsers = (Get-Process explorer -ErrorAction SilentlyContinue).Count +$userColor = if ($loggedUsers -gt 0) { "Yellow" } else { "Green" } +Write-Host "Użytkownicy: " -NoNewline +Write-Host "$loggedUsers zalogowanych sesji graficznych" -ForegroundColor $userColor + +# 3. Czas działania (Uptime) i ostatni restart +$os = Get-CimInstance Win32_OperatingSystem +$lastBoot = $os.LastBootUpTime +$uptime = (Get-Date) - $lastBoot +Write-Host "Uptime: " -NoNewline +Write-Host "$($uptime.Days) dni, $($uptime.Hours) godz, $($uptime.Minutes) min (Uruchomiono: $lastBoot)" -ForegroundColor White + +# 4. Zużycie RAM +$totalRamGb = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2) +$freeRamGb = [math]::Round($os.FreePhysicalMemory / 1MB, 2) +$usedRamGb = $totalRamGb - $freeRamGb +$ramPercent = [math]::Round(($usedRamGb / $totalRamGb) * 100, 1) + +$ramColor = if ($ramPercent -ge 90) { "Red" } elseif ($ramPercent -ge 75) { "Yellow" } else { "Green" } +Write-Host "RAM: " -NoNewline +Write-Host "$usedRamGb GB zajęte z $totalRamGb GB ($ramPercent%)" -ForegroundColor $ramColor + +Write-Host "==========================================" -ForegroundColor Cyan \ No newline at end of file diff --git a/ShowMessage.ps1 b/ShowMessage.ps1 new file mode 100644 index 0000000..dffb96e --- /dev/null +++ b/ShowMessage.ps1 @@ -0,0 +1,63 @@ +# ShowMessage.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +param ( + [Parameter(Mandatory=$true, Position=0, HelpMessage="Treść wiadomości")] + [string]$Message, + + [Parameter(Mandatory=$true, Position=1, HelpMessage="Typ komunikatu: 1 (Info), 2 (Ostrzeżenie), 3 (Błąd)")] + [ValidateSet("1", "2", "3")] + [string]$Type +) + +# Znajdujemy ID sesji aktywnego użytkownika fizycznego (konsoli) +$sessionId = (Get-Process explorer -ErrorAction SilentlyContinue | Select-Object -First 1).SessionId + +if ($null -eq $sessionId) { + Write-Host "[BŁĄD] Nie wykryto zalogowanego użytkownika z interfejsem graficznym." -ForegroundColor Red + Exit +} + +# Dobór tytułu okna oraz ikonki w zależności od wybranego typu +switch ($Type) { + "1" { + $title = "Komunikat informacyjny" + # msg.exe nie obsługuje bezpośrednio ikonek, ale możemy użyć VBScript/PowerShell Windows Forms, + # jednak klasyczny msg.exe jest najprostszy. Zróbmy to przez okno Forms dla pełnej kontroli typów! + } + "2" { $title = "Ostrzeżenie" } + "3" { $title = "Błąd" } +} + +# Użycie .NET Windows Forms pozwala na wyświetlenie prawdziwego okna z odpowiednią ikoną w sesji użytkownika +$scriptBlock = { + param($msg, $t, $sessionIdToUse) + + # Ładujemy wymagane biblioteki GUI + Add-Type -AssemblyName PresentationFramework + Add-Type -AssemblyName System.Windows.Forms + + switch ($t) { + "1" { [System.Windows.Forms.MessageBox]::Show($msg, "Informacja", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information) } + "2" { [System.Windows.Forms.MessageBox]::Show($msg, "Ostrzeżenie", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning) } + "3" { [System.Windows.Forms.MessageBox]::Show($msg, "Błąd", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) } + } +} + +# Uruchomienie skryptu w kontekście sesji aktywnego użytkownika za pomocą harmonogramu zadań lub joba sesyjnego +# Najprostsza metoda "zdalna do lokalnej sesji" w PowerShell to użycie Invoke-Command na sesję lokalną lub msg.exe +# Zastosujmy niezawodny natywny mechanizm msg.exe, który automatycznie trafia na ekran aktualnego użytkownika: + +# Mapowanie naszego typu na parametry przełączników msg (choć msg ma ograniczone opcje, lepiej użyć wywołania msg) +# Tytuł dla msg jest domyślnie nagłówkiem, a ikona zależy od systemu. +# Zróbmy to elegancko przez msg.exe: + +switch ($Type) { + "1" { $prefix = "[INFORMACJA]" } + "2" { $prefix = "[OSTRZEŻENIE]" } + "3" { $prefix = "[BŁĄD]" } +} + +# Polecenie msg wysyła okno dialogowe bezpośrednio do aktywnej sesji graficznej konsoli (*) +msg * /TIME:0 "$prefix $Message" \ No newline at end of file diff --git a/ToggleAccount.ps1 b/ToggleAccount.ps1 new file mode 100644 index 0000000..35358de --- /dev/null +++ b/ToggleAccount.ps1 @@ -0,0 +1,25 @@ +# ToggleAccount.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +param ( + [Parameter(Mandatory=$true, HelpMessage="Podaj nazwę konta użytkownika")] + [string]$AccountName +) + +try { + # Pobieramy obiekt użytkownika. Jeśli nie istnieje, przechodzimy do bloku catch. + $user = Get-LocalUser -Name $AccountName -ErrorAction Stop + + if ($user.Enabled) { + Disable-LocalUser -Name $AccountName + Write-Host "[INFO] Konto '$AccountName' zostało WYŁĄCZONE." -ForegroundColor Yellow + } else { + Enable-LocalUser -Name $AccountName + Write-Host "[INFO] Konto '$AccountName' zostało WŁĄCZONE." -ForegroundColor Green + } +} catch [Microsoft.PowerShell.Commands.UserNotFoundException] { + Write-Host "[BŁĄD] Nie znaleziono konta o nazwie '$AccountName'." -ForegroundColor Red +} catch { + Write-Host "[BŁĄD] Wystąpił nieoczekiwany problem:" -ForegroundColor Red +} \ No newline at end of file diff --git a/ToggleWifiCard.ps1 b/ToggleWifiCard.ps1 new file mode 100644 index 0000000..c8840f8 --- /dev/null +++ b/ToggleWifiCard.ps1 @@ -0,0 +1,35 @@ +# ToggleWifiCard.ps1 +# Wymaga uruchomienia z uprawnieniami Administratora +#Requires -RunAsAdministrator + +Write-Host "Wyszukiwanie kart sieciowych Wi-Fi..." -ForegroundColor Cyan + +# Szukamy kart po fizycznym typie nośnika (niezależnie od tego, jak uczeń/system nazwał interfejs) +$wifiAdapters = Get-NetAdapter | Where-Object { $_.PhysicalMediaType -eq 'Native 802.11' } + +if (-not $wifiAdapters) { + Write-Host "[BŁĄD] Nie znaleziono żadnej fizycznej karty Wi-Fi na tym komputerze." -ForegroundColor Red + Exit +} + +foreach ($adapter in $wifiAdapters) { + try { + # Stan 'Disabled' oznacza, że karta jest wyłączona sprzętowo/w menedżerze urządzeń + if ($adapter.Status -eq 'Disabled') { + Write-Host "[INFO] Karta '$($adapter.Name)' jest WYŁĄCZONA. Trwa włączanie..." -NoNewline + + # Włączamy kartę. Parametr -Confirm:$false zapobiega wyskakiwaniu okienka z zapytaniem + Enable-NetAdapter -Name $adapter.Name -Confirm:$false -ErrorAction Stop + Write-Host " GOTOWE (WŁĄCZONO)" -ForegroundColor Green + } else { + Write-Host "[INFO] Karta '$($adapter.Name)' jest WŁĄCZONA. Trwa wyłączanie..." -NoNewline + + # Wyłączamy kartę + Disable-NetAdapter -Name $adapter.Name -Confirm:$false -ErrorAction Stop + Write-Host " GOTOWE (WYŁĄCZONO)" -ForegroundColor Yellow + } + } catch { + Write-Host " BŁĄD" -ForegroundColor Red + Write-Host " Szczegóły: $_" -ForegroundColor Red + } +} \ No newline at end of file