1. sayfa (Toplam 1 sayfa)

İşinize Yarayacak İki PowerShell Betiği

Gönderilme zamanı: 01 Ağu 2026, 08:25
gönderen TRWE_2012
Merhabalar

Windows Service Manager v2.1.ps1

Kod: Tümünü seç

# ============================================================
# Service Management Tool v2.1
# Author       : TRWE_2012
# Development  : TRWE_2012
# System       : Windows 11 - Service Control Manager
# ============================================================

# ------------------------------------------------------------
# FUNCTIONS
# ------------------------------------------------------------

function Exit-Script {
    param([int]$Code = 0)
    Write-Host "Exiting..." -ForegroundColor Yellow
    exit $Code
}

function Show-Header {
    Clear-Host
    Write-Host "============================================" -ForegroundColor Blue
    Write-Host "  Service Management Tool v2.1             " -ForegroundColor Blue
    Write-Host "============================================" -ForegroundColor Blue
    Write-Host ""
}

function Show-ServiceStatus {
    param([string]$ServiceName)

    Write-Host "--- Service Information ---" -ForegroundColor Blue

    $svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
    if (-not $svc) {
        Write-Host "Error: Service not found -> $ServiceName" -ForegroundColor Red
        return
    }

    Write-Host "Name           : $($svc.Name)"
    Write-Host "Display Name   : $($svc.DisplayName)"

    Write-Host -NoNewline "Running State  : "
    if ($svc.Status -eq 'Running') {
        Write-Host "Running" -ForegroundColor Green
    } else {
        Write-Host "$($svc.Status)" -ForegroundColor Red
    }

    Write-Host -NoNewline "Startup Type   : "
    switch ($svc.StartType) {
        'Automatic' { Write-Host "Automatic" -ForegroundColor Green }
        'Manual'    { Write-Host "Manual" -ForegroundColor Yellow }
        'Disabled'  { Write-Host "Disabled" -ForegroundColor Red }
        default     { Write-Host "$($svc.StartType)" -ForegroundColor Yellow }
    }
    Write-Host ""
}

function Show-ServiceList {
    Show-Header
    Write-Host "--- Services on System ---" -ForegroundColor Blue
    Write-Host ""

    $allServices = Get-Service
    $totalCount     = $allServices.Count
    $runningCount   = ($allServices | Where-Object { $_.Status -eq 'Running' }).Count
    $stoppedCount   = ($allServices | Where-Object { $_.Status -eq 'Stopped' }).Count
    $automaticCount = ($allServices | Where-Object { $_.StartType -eq 'Automatic' }).Count
    $manualCount    = ($allServices | Where-Object { $_.StartType -eq 'Manual' }).Count
    $disabledCount  = ($allServices | Where-Object { $_.StartType -eq 'Disabled' }).Count

    Write-Host "--- Overview ---" -ForegroundColor Blue
    Write-Host "Total services       : $totalCount"
    Write-Host -NoNewline "Running              : "
    Write-Host "$runningCount" -ForegroundColor Green
    Write-Host -NoNewline "Stopped              : "
    Write-Host "$stoppedCount" -ForegroundColor Red
    Write-Host -NoNewline "Automatic startup    : "
    Write-Host "$automaticCount" -ForegroundColor Green
    Write-Host -NoNewline "Manual startup       : "
    Write-Host "$manualCount" -ForegroundColor Yellow
    Write-Host -NoNewline "Disabled startup     : "
    Write-Host "$disabledCount" -ForegroundColor Red
    Write-Host ""

    Write-Host "Select a filter:" -ForegroundColor Blue
    Write-Host "  1 - All services"
    Write-Host "  2 - Running services only"
    Write-Host "  3 - Stopped services only"
    Write-Host "  4 - Automatic startup only"
    Write-Host "  5 - Disabled startup only"
    Write-Host "  6 - Manual startup only"
    Write-Host "  7 - Back to menu"
    Write-Host ""
    $filterChoice = Read-Host "Your choice [1-7]"

    Write-Host ""
    switch ($filterChoice) {
        '1' {
            Write-Host "Listing all services..." -ForegroundColor Yellow
            Write-Host ""
            $result = Get-Service | Sort-Object Name
            $result | Format-Table Name, DisplayName, Status, StartType -AutoSize | Out-Host
            Write-Host "Total count : $($result.Count)" -ForegroundColor Blue
        }
        '2' {
            Write-Host "Running services:" -ForegroundColor Green
            Write-Host ""
            $result = Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name
            $result | Format-Table Name, DisplayName, Status, StartType -AutoSize | Out-Host
            Write-Host "Total count : $($result.Count)" -ForegroundColor Blue
        }
        '3' {
            Write-Host "Stopped services:" -ForegroundColor Red
            Write-Host ""
            $result = Get-Service | Where-Object { $_.Status -eq 'Stopped' } | Sort-Object Name
            $result | Format-Table Name, DisplayName, Status, StartType -AutoSize | Out-Host
            Write-Host "Total count : $($result.Count)" -ForegroundColor Blue
        }
        '4' {
            Write-Host "Services with Automatic startup:" -ForegroundColor Green
            Write-Host ""
            $result = Get-Service | Where-Object { $_.StartType -eq 'Automatic' } | Sort-Object Name
            $result | Format-Table Name, DisplayName, Status, StartType -AutoSize | Out-Host
            Write-Host "Total count : $($result.Count)" -ForegroundColor Blue
        }
        '5' {
            Write-Host "Services with Disabled startup:" -ForegroundColor Yellow
            Write-Host ""
            $result = Get-Service | Where-Object { $_.StartType -eq 'Disabled' } | Sort-Object Name
            $result | Format-Table Name, DisplayName, Status, StartType -AutoSize | Out-Host
            Write-Host "Total count : $($result.Count)" -ForegroundColor Blue
        }
        '6' {
            Write-Host "Services with Manual startup:" -ForegroundColor Yellow
            Write-Host ""
            $result = Get-Service | Where-Object { $_.StartType -eq 'Manual' } | Sort-Object Name
            $result | Format-Table Name, DisplayName, Status, StartType -AutoSize | Out-Host
            Write-Host "Total count : $($result.Count)" -ForegroundColor Blue
        }
        '7' { return }
        default {
            Write-Host "Invalid selection." -ForegroundColor Red
        }
    }
    Write-Host ""
    Read-Host "Press Enter to continue" | Out-Null
}

# ------------------------------------------------------------
# CHECKS
# ------------------------------------------------------------

# Administrator privilege check
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal($currentIdentity)
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (-not $isAdmin) {
    Write-Host "Warning: This script is not running as Administrator." -ForegroundColor Yellow
    Write-Host "Some operations (start type changes, service start/stop) will fail without elevation." -ForegroundColor Yellow
    Write-Host ""
}

# Service Control Manager availability check (Get-Service cmdlet)
if (-not (Get-Command Get-Service -ErrorAction SilentlyContinue)) {
    Write-Host "Error: Get-Service cmdlet is not available on this system." -ForegroundColor Red
    Exit-Script 1
}

# ------------------------------------------------------------
# MAIN MENU
# ------------------------------------------------------------

while ($true) {
    Show-Header
    Write-Host "--- Main Menu ---" -ForegroundColor Blue
    Write-Host "  1 - List Services"
    Write-Host "  2 - Manage Service (Automatic/Manual/Disabled)"
    Write-Host "  3 - Exit"
    Write-Host ""
    $mainChoice = Read-Host "Your choice [1-3]"

    switch ($mainChoice) {
        '1' {
            Show-ServiceList
        }
        '2' {
            Show-Header

            $serviceName = Read-Host "Enter service name (example: Spooler)"

            if ([string]::IsNullOrWhiteSpace($serviceName)) {
                Write-Host "Empty input. Operation cancelled." -ForegroundColor Yellow
                Start-Sleep -Seconds 1
                continue
            }

            $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
            if (-not $service) {
                Write-Host "Error: Service not found -> $serviceName" -ForegroundColor Red
                Read-Host "Press Enter to continue" | Out-Null
                continue
            }

            Write-Host ""
            Show-ServiceStatus -ServiceName $serviceName

            Write-Host "--- Select Startup Type ---" -ForegroundColor Blue
            Write-Host "  1 - Automatic  : Starts automatically at system boot"
            Write-Host "  2 - Manual     : Does not start automatically at boot"
            Write-Host "  3 - Disabled   : Fully locked, cannot be started"
            Write-Host "  4 - Re-enable  : Restore to Manual after Disabled"
            Write-Host "  5 - Back"
            Write-Host ""
            $actionChoice = Read-Host "Your choice [1-5]"

            $startType = $null
            switch ($actionChoice) {
                '1' { $startType = 'Automatic' }
                '2' { $startType = 'Manual' }
                '3' { $startType = 'Disabled' }
                '4' { $startType = 'Manual' }
                '5' { continue }
                default {
                    Write-Host "Invalid selection." -ForegroundColor Red
                    Read-Host "Press Enter to continue" | Out-Null
                    continue
                }
            }

            Write-Host ""
            Write-Host "Action  : Set startup type to $startType" -ForegroundColor Yellow
            Write-Host "Service : $serviceName" -ForegroundColor Yellow
            Write-Host ""
            $confirm = Read-Host "Proceed? (y/n)"

            if ($confirm -ne 'y' -and $confirm -ne 'Y') {
                Write-Host "Operation cancelled." -ForegroundColor Yellow
                Read-Host "Press Enter to continue" | Out-Null
                continue
            }

            Write-Host ""
            try {
                Set-Service -Name $serviceName -StartupType $startType -ErrorAction Stop

                if ($startType -eq 'Disabled' -and $service.Status -eq 'Running') {
                    Stop-Service -Name $serviceName -ErrorAction SilentlyContinue
                }

                Write-Host "Operation completed successfully." -ForegroundColor Green
                Write-Host ""
                Show-ServiceStatus -ServiceName $serviceName
            } catch {
                Write-Host "Error: Operation failed -> $($_.Exception.Message)" -ForegroundColor Red
            }
            Read-Host "Press Enter to continue" | Out-Null
        }
        '3' {
            Exit-Script 0
        }
        default {
            Write-Host "Invalid selection." -ForegroundColor Red
            Start-Sleep -Seconds 1
        }
    }
}

Read-Host "`nPress ENTER to exit."
Resim
*************************************************************************************

Directory Inventory Lister.ps1

Kod: Tümünü seç

# ============================================================
# Directory Inventory Lister (Recursive Browser)
# System : Windows 11
# ============================================================

function Show-Header {
    Clear-Host
    Write-Host "============================================" -ForegroundColor Blue
    Write-Host "  Directory Inventory Lister                " -ForegroundColor Blue
    Write-Host "============================================" -ForegroundColor Blue
    Write-Host ""
}

function Remove-TargetItem {
    param([System.IO.FileSystemInfo]$Item)

    if (-not (Test-Path -LiteralPath $Item.FullName)) {
        Write-Host "This item was already deleted or no longer exists." -ForegroundColor Yellow
        return
    }

    $confirmDelete = Read-Host "Delete '$($Item.Name)'? (yes/no)"
    if ($confirmDelete -match '^(y|yes)$') {
        try {
            if ($Item.PSIsContainer) {
                Remove-Item -LiteralPath $Item.FullName -Recurse -Force -ErrorAction Stop
            } else {
                Remove-Item -LiteralPath $Item.FullName -Force -ErrorAction Stop
            }
            Write-Host "'$($Item.Name)' permanently deleted." -ForegroundColor Green
        } catch {
            Write-Host "Error: Could not delete item -> $($_.Exception.Message)" -ForegroundColor Red
        }
    } else {
        Write-Host "Deletion cancelled." -ForegroundColor Yellow
    }
}

function Invoke-DirectoryBrowser {
    param([string]$Path)

    while ($true) {
        Show-Header
        Write-Host "Path: $Path" -ForegroundColor Blue
        Write-Host ""

        if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
            Write-Host "Error: Directory no longer exists -> $Path" -ForegroundColor Red
            Read-Host "Press Enter to go back" | Out-Null
            return
        }

        $items = @(Get-ChildItem -LiteralPath $Path -Force)

        Write-Host "--- Items in Directory (all types) ---" -ForegroundColor Blue
        if ($items.Count -eq 0) {
            Write-Host "No items found in this directory." -ForegroundColor Yellow
        } else {
            for ($i = 0; $i -lt $items.Count; $i++) {
                $typeLabel = if ($items[$i].PSIsContainer) { "[DIR]" } else { "[FILE]" }
                Write-Host ("{0,3} - {1,-6} {2}" -f ($i + 1), $typeLabel, $items[$i].Name)
            }
            Write-Host ""
            Write-Host "Total items: $($items.Count)" -ForegroundColor Blue
        }

        $subDirs = @($items | Where-Object { $_.PSIsContainer })
        Write-Host ""
        Write-Host "--- Subdirectories ---" -ForegroundColor Blue
        if ($subDirs.Count -eq 0) {
            Write-Host "No subdirectories found." -ForegroundColor Yellow
        } else {
            for ($i = 0; $i -lt $subDirs.Count; $i++) {
                Write-Host ("{0,3} - {1}" -f ($i + 1), $subDirs[$i].Name)
            }
            Write-Host "Total subdirectories: $($subDirs.Count)" -ForegroundColor Blue
        }

        Write-Host ""
        if ($items.Count -eq 0) {
            Read-Host "Press Enter to go back" | Out-Null
            return
        }

        $numberInput = Read-Host "Enter the sequence number of the object (or press Enter to go back)"

        if ([string]::IsNullOrWhiteSpace($numberInput)) {
            return
        }

        $selectedIndex = 0
        if (-not [int]::TryParse($numberInput, [ref]$selectedIndex) -or $selectedIndex -lt 1 -or $selectedIndex -gt $items.Count) {
            Write-Host "Invalid number." -ForegroundColor Red
            Read-Host "Press Enter to continue" | Out-Null
            continue
        }

        $selectedItem = $items[$selectedIndex - 1]

        if ($selectedItem.PSIsContainer) {
            Write-Host ""
            Write-Host "'$($selectedItem.Name)' is a directory." -ForegroundColor Blue
            Write-Host "  1 - View contents (browse inside)"
            Write-Host "  2 - Delete directly (including all contents)"
            Write-Host "  3 - Cancel"
            $subChoice = Read-Host "Your choice [1-3]"

            switch ($subChoice) {
                '1' { Invoke-DirectoryBrowser -Path $selectedItem.FullName }
                '2' { Remove-TargetItem -Item $selectedItem; Read-Host "Press Enter to continue" | Out-Null }
                default { Write-Host "Cancelled." -ForegroundColor Yellow; Start-Sleep -Seconds 1 }
            }
        } else {
            Remove-TargetItem -Item $selectedItem
            Read-Host "Press Enter to continue" | Out-Null
        }
    }
}

# --- GET TARGET DIRECTORY FROM USER ---
Show-Header
$targetDir = Read-Host "Enter the full path of the directory to inspect"

if (-not (Test-Path -LiteralPath $targetDir -PathType Container)) {
    Write-Host "Error: Directory not found -> $targetDir" -ForegroundColor Red
    Read-Host "`nPress ENTER to exit."
    exit 1
}

Invoke-DirectoryBrowser -Path $targetDir

Read-Host "`nPress ENTER to exit."
Kullanılması :

1.Masaüstün bir "Yeni Klasör" oluşturun.
2.Bu "Yeni Klasörün" içine bir kaç tane alakasız nesne atın.
3.Bu "Yeni Klasörün" içinde bir ALT DİZİN oluşturun, içine bir kaç nesne atın.
4.Sonra, betiği yönetici olarak çalıştırıp , Masaüstünde oluşturduğunuz "Yeni Klasör" ana dizinin yolunu betiğe gösterin ve betiği Yeni Klasör üzerinden "KURCALAYIN" eminim birçoğunuzun işine yarayacaktır bu betik...

BONUS :

Doğrudan Masaüstüne PS Betiğinin Kısayolunu Oluşturan Betik...

Create-Ps1-Shortcut.ps1

Kod: Tümünü seç

# ============================================================
# PowerShell Script Shortcut Creator
# System : Windows 11
# ============================================================

function Show-Header {
    Clear-Host
    Write-Host "============================================" -ForegroundColor Blue
    Write-Host "  PowerShell Script Shortcut Creator        " -ForegroundColor Blue
    Write-Host "============================================" -ForegroundColor Blue
    Write-Host ""
}

Show-Header

# --- GET SCRIPT PATH FROM USER ---
$scriptPath = Read-Host "Enter the full path of the .ps1 script"

if (-not (Test-Path -LiteralPath $scriptPath -PathType Leaf)) {
    Write-Host "Error: File not found -> $scriptPath" -ForegroundColor Red
    Read-Host "`nPress ENTER to exit."
    exit 1
}

if ([System.IO.Path]::GetExtension($scriptPath) -ne ".ps1") {
    Write-Host "Error: The specified file is not a .ps1 script." -ForegroundColor Red
    Read-Host "`nPress ENTER to exit."
    exit 1
}

$resolvedPath = (Resolve-Path -LiteralPath $scriptPath).Path
$scriptName = [System.IO.Path]::GetFileNameWithoutExtension($resolvedPath)

# --- ASK WHETHER TO KEEP THE WINDOW OPEN AFTER THE SCRIPT ENDS ---
$keepOpenInput = Read-Host "Keep the PowerShell window open after the script finishes? (yes/no)"
$noExitFlag = if ($keepOpenInput -match '^(y|yes)$') { "-NoExit " } else { "" }

# --- DETERMINE DESKTOP PATH (locale-independent) ---
$desktopPath = [Environment]::GetFolderPath("Desktop")
$shortcutPath = Join-Path $desktopPath "$scriptName.lnk"

if (Test-Path -LiteralPath $shortcutPath) {
    $overwrite = Read-Host "A shortcut named '$scriptName.lnk' already exists on the Desktop. Overwrite it? (yes/no)"
    if ($overwrite -notmatch '^(y|yes)$') {
        Write-Host "Operation cancelled." -ForegroundColor Yellow
        Read-Host "`nPress ENTER to exit."
        exit 0
    }
}

# --- CREATE THE SHORTCUT ---
try {
    $wshShell = New-Object -ComObject WScript.Shell
    $shortcut = $wshShell.CreateShortcut($shortcutPath)

    $shortcut.TargetPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
    $shortcut.Arguments = "$($noExitFlag)-ExecutionPolicy Bypass -File `"$resolvedPath`""
    $shortcut.WorkingDirectory = [System.IO.Path]::GetDirectoryName($resolvedPath)
    $shortcut.IconLocation = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe,0"
    $shortcut.Description = "Shortcut for $scriptName.ps1"
    $shortcut.Save()

    Write-Host ""
    Write-Host "Shortcut created successfully:" -ForegroundColor Green
    Write-Host $shortcutPath -ForegroundColor Green
} catch {
    Write-Host ""
    Write-Host "Error: Could not create shortcut -> $($_.Exception.Message)" -ForegroundColor Red
}

Read-Host "`nPress ENTER to exit."
Böylece masaüstünde oluşturulan kısayola direkt tıklayabilirsiniz.(kısıtlama betik tarafından hallediliyor)

Re: İşinize Yarayacak İki PowerShell Betiği

Gönderilme zamanı: 01 Ağu 2026, 10:00
gönderen burak35
saçmalığa bakar mısın ? windows 11 çöpünde 282 tane servis hizmet var ? işte bu bile windows 11 çöpünü kullanmamak için bir nedendir.
bu kadar servisi hizmeti ne yapacaksın ey aptal hintli ? görende hintliler bütün kahinatı yönetiyor sanacak. o kadar fazla,
o kadar gereksiz ki o servisler. düz hesap 300 de artık. lanet olsun şu pis hintlilere güç kuvvet yönetim verenlere.
adamların yaptıkları çöp sistem o kadar şişik bi sistem ki. servis hizmet sayısından bile anlayabiliyorsunuz.