Skip to content

OP Windows Wand #12558

Closed
Closed
@NeoMachine35

Description

@NeoMachine35

What would you like to share?

# PowerShell Script for Windows 10/11 Remedial Tasks
# Author: OP The Magician 
# Version: 1.0
# Description: Provides an interactive menu to select and execute common troubleshooting and repair tasks.

# Function to display the menu
function Show-Menu {
    Clear-Host
    Write-Host "==================================="
    Write-Host " Windows 10/11 Remedial Task Script"
    Write-Host "==================================="
    Write-Host "1. System File Checker (SFC)"
    Write-Host "2. DISM (Deployment Imaging Service and Management Tool)"
    Write-Host "3. Check Disk (CHKDSK)"
    Write-Host "4. Windows Update Troubleshooter"
    Write-Host "5. Reset Windows Update Components"
    Write-Host "6. Clear Temp Files"
    Write-Host "7. Repair Windows Store Apps"
    Write-Host "8. Flush DNS Cache"
    Write-Host "9. Restart Windows Explorer"
    Write-Host "10. Scan for Malware (Windows Defender)"
    Write-Host "11. Check for Windows Updates"
    Write-Host "12. Reset Network Settings"
    Write-Host "13. Uninstall Recent Updates"
    Write-Host "14. Rebuild Search Index"
    Write-Host "15. Perform a System Restore"
    Write-Host "16. Check for Driver Updates"
    Write-Host "17. Enable Safe Mode"
    Write-Host "18. Disable Startup Programs"
    Write-Host "19. Check Event Viewer for Errors"
    Write-Host "20. Run Disk Cleanup"
    Write-Host "-----------------------------"
    Write-Host "21. Install Update for Windows Management Framework (WMF)"
    Write-Host "22. Install Power BI Desktop"
    Write-Host "23. Install Azure Data Studio"
    Write-Host "24. Install Visual Studio Tools for Applications (VSTA)"
    Write-Host "25. Install Microsoft Management Console (MMC)"
    Write-Host "26. Install Windows Assessment and Deployment Kit (ADK)"
    Write-Host "27. Install Windows Assessment and Deployment Kit (ADK) for Windows 10"
    Write-Host "28. Install Windows Configuration Designer"
    Write-Host "29. Install Group Policy Management Console (GPMC)"
    Write-Host "30. Install Windows Management Instrumentation (WMI)"
    Write-Host "-----------------------------"
    Write-Host "31. Backup Selected Registry Keys"
    Write-Host "32. Restore Selected Registry Keys"
    Write-Host "33. Change BIOS Settings (BCDEdit)"
    Write-Host "34. Change Windows Date and Time Settings"
    Write-Host "35. Change Windows Power Settings"
    Write-Host "36. Change Windows Region Settings"
    Write-Host "37. Change Windows Shell Icon"
    Write-Host "38. Change Windows Display Settings"
    Write-Host "39. Change Windows IME Settings"
    Write-Host "40. Change Windows Network and Sharing Center Settings"
    Write-Host "Q. Quit"
    Write-Host "==================================="
}

# Function to execute the selected task
function Execute-Task {
    param (
        [int]$Choice
    )

    switch ($Choice) {
        1 {
            Write-Host "Running System File Checker (SFC)..."
            Start-Process "sfc" -ArgumentList "/scannow" -NoNewWindow -Wait
        }
        2 {
            Write-Host "Running DISM (Deployment Imaging Service and Management Tool)..."
            Start-Process "dism" -ArgumentList "/online /cleanup-image /restorehealth" -NoNewWindow -Wait
        }
        3 {
            Write-Host "Running Check Disk (CHKDSK)..."
            Start-Process "chkdsk" -ArgumentList "/f /r" -NoNewWindow -Wait
        }
        4 {
            Write-Host "Running Windows Update Troubleshooter..."
            Start-Process "msdt.exe" -ArgumentList "/id WindowsUpdateDiagnostic" -NoNewWindow -Wait
        }
        5 {
            Write-Host "Resetting Windows Update Components..."
            Stop-Service -Name wuauserv -Force
            Stop-Service -Name bits -Force
            Remove-Item "$env:systemroot\SoftwareDistribution\*" -Recurse -Force
            Start-Service -Name wuauserv
            Start-Service -Name bits
            Write-Host "Windows Update components have been reset."
        }
        6 {
            Write-Host "Clearing Temp Files..."
            Remove-Item "$env:temp\*" -Recurse -Force
            Remove-Item "$env:windir\Temp\*" -Recurse -Force
            Write-Host "Temp files have been cleared."
        }
        7 {
            Write-Host "Repairing Windows Store Apps..."
            Get-AppXPackage | ForEach-Object { Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml" }
            Write-Host "Windows Store apps have been repaired."
        }
        8 {
            Write-Host "Flushing DNS Cache..."
            Start-Process "ipconfig" -ArgumentList "/flushdns" -NoNewWindow -Wait
            Write-Host "DNS cache has been flushed."
        }
        9 {
            Write-Host "Restarting Windows Explorer..."
            Stop-Process -Name explorer -Force
            Start-Process "explorer"
            Write-Host "Windows Explorer has been restarted."
        }
        10 {
            Write-Host "Scanning for Malware with Windows Defender..."
            Start-Process "mpcmdrun" -ArgumentList "-Scan -ScanType 1" -NoNewWindow -Wait
            Write-Host "Malware scan completed."
        }
        11 {
            Write-Host "Checking for Windows Updates..."
            Start-Process "wuauclt" -ArgumentList "/detectnow" -NoNewWindow -Wait
            Write-Host "Windows Update check initiated."
        }
        12 {
            Write-Host "Resetting Network Settings..."
            Start-Process "netsh" -ArgumentList "winsock reset" -NoNewWindow -Wait
            Start-Process "netsh" -ArgumentList "int ip reset" -NoNewWindow -Wait
            Write-Host "Network settings have been reset."
        }
        13 {
            Write-Host "Uninstalling Recent Updates..."
            Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 5 | ForEach-Object {
                Start-Process "wusa" -ArgumentList "/uninstall /kb:$($_.HotFixID) /quiet" -NoNewWindow -Wait
            }
            Write-Host "Recent updates have been uninstalled."
        }
        14 {
            Write-Host "Rebuilding Search Index..."
            Stop-Service -Name "WSearch" -Force
            Remove-Item "$env:ProgramData\Microsoft\Search\Data\*" -Recurse -Force
            Start-Service -Name "WSearch"
            Write-Host "Search index has been rebuilt."
        }
        15 {
            Write-Host "Performing a System Restore..."
            Start-Process "rstrui" -NoNewWindow -Wait
            Write-Host "System Restore launched."
        }
        16 {
            Write-Host "Checking for Driver Updates..."
            Start-Process "devmgmt.msc" -NoNewWindow -Wait
            Write-Host "Device Manager launched. Please check for driver updates manually."
        }
        17 {
            Write-Host "Enabling Safe Mode..."
            Start-Process "bcdedit" -ArgumentList "/set {current} safeboot minimal" -NoNewWindow -Wait
            Write-Host "Safe Mode has been enabled. Restart your computer to enter Safe Mode."
        }
        18 {
            Write-Host "Disabling Startup Programs..."
            Start-Process "msconfig" -NoNewWindow -Wait
            Write-Host "System Configuration launched. Please disable startup programs manually."
        }
        19 {
            Verify-WindowsEventLogError
        }
        20 {
            Write-Host "Running Disk Cleanup..."
            Start-Process "cleanmgr" -NoNewWindow -Wait
        }
        21 {
            Install-WindowsManagementFramework
        }
        22 {
            Install-PowerBI
        }
        23 {
            Install-AzureDataStudio
        }
        24 {
            Install-VSTA
        }
        25 {
            Install-MMC
        }
        26 {
            Install-ADK
        }
        27 {
            Install-ADKWin10
        }
        28 {
            Install-WindowsConfigurationDesigner
        }
        29 {
            Install-GPMC
        }
        30 {
            Install-WMI
        }
        31 {
            Backup-RegistryKeys
        }
        32 {
            Restore-RegistryKeys
        }
        33 {
            Change-BIOSSettingsBCDEdit
        }
        34 {
            Change-WindowsDateAndTime
        }
        35 {
            Change-WindowsPowerSettings
        }
        36 {
            Change-WindowsRegionSettings
        }
        37 {
            Change-WindowsShellIcon
        }
        38 {
            Change-WindowsDisplaySettings
        }
        39 {
            Change-WindowsIMESettings
        }
        40 {
            Change-WindowsNetworkAndSharingCenterSettings
        }
        41 {
            Write-Host "Exiting script..."
            Exit
        }
        default {
            Write-Host "Invalid choice. Please try again."
        }
    }
}

# Function to verify Windows Event Log for errors
function Verify-WindowsEventLogError {
    Write-Host "Checking Event Viewer for Errors..."
    Get-EventLog -LogName System -After (Get-Date).AddDays(-7) | Where-Object { $_.EntryType -eq 'Error' -or $_.EntryType -eq 'Critical' } | Select-Object -First 10
    Write-Host "Checked Event Viewer for errors. Review the output for any critical issues."
}

# Function to install Windows Management Framework
function Install-WindowsManagementFramework {
    Write-Host "Installing Windows Management Framework (WMF)... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2138039" -OutFile "$env:TEMP\WindowsManagementFrameworkSetup.exe"
    Start-Process "$env:TEMP\WindowsManagementFrameworkSetup.exe" -ArgumentList "/quiet /norestart" -Wait
    Remove-Item "$env:TEMP\WindowsManagementFrameworkSetup.exe"
    Write-Host "Windows Management Framework has been installed."
}

# Function to install Power BI Desktop
function Install-PowerBI {
    Write-Host "Installing Power BI Desktop..."
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2136915" -OutFile "$env:TEMP\PowerBI.Desktop.msi"
    Start-Process msiexec.exe -ArgumentList "/i $env:TEMP\PowerBI.Desktop.msi /quiet" -Wait
    Remove-Item "$env:TEMP\PowerBI.Desktop.msi"
    Write-Host "Power BI Desktop has been installed."
}

# Function to install Azure Data Studio
function Install-AzureDataStudio {
    Write-Host "Installing Azure Data Studio..."
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=2059969" -OutFile "$env:TEMP\AzureDataStudioSetup.exe"
    Start-Process "$env:TEMP\AzureDataStudioSetup.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\AzureDataStudioSetup.exe"
    Write-Host "Azure Data Studio has been installed."
}

# Function to install Visual Studio Tools for Applications (VSTA)
function Install-VSTA {
    Write-Host "Installing Visual Studio Tools for Applications (VSTA)... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=2059968" -OutFile "$env:TEMP\VSTASetup.exe"
    Start-Process "$env:TEMP\VSTASetup.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\VSTASetup.exe"
    Write-Host "Visual Studio Tools for Applications has been installed."
}

# Function to install Microsoft Management Console (MMC)
function Install-MMC {
    Write-Host "Installing Microsoft Management Console (MMC)... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2138043" -OutFile "$env:TEMP\MMCSetup.exe"
    Start-Process "$env:TEMP\MMCSetup.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\MMCSetup.exe"
    Write-Host "Microsoft Management Console has been installed."
}

# Function to install Windows Assessment and Deployment Kit (ADK)
function Install-ADK {
    Write-Host "Installing Windows Assessment and Deployment Kit (ADK)... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2138041" -OutFile "$env:TEMP\ADKSetup.exe"
    Start-Process "$env:TEMP\ADKSetup.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\ADKSetup.exe"
    Write-Host "Windows Assessment and Deployment Kit has been installed."
}

# Function to install Windows Assessment and Deployment Kit (ADK) for Windows 10
function Install-ADKWin10 {
    Write-Host "Installing Windows Assessment and Deployment Kit (ADK) for Windows 10... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2138042" -OutFile "$env:TEMP\ADKSetup-Win10.exe"
    Start-Process "$env:TEMP\ADKSetup-Win10.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\ADKSetup-Win10.exe"
    Write-Host "Windows Assessment and Deployment Kit for Windows 10 has been installed."
}

# Function to install Windows Configuration Designer
function Install-WindowsConfigurationDesigner {
    Write-Host "Installing Windows Configuration Designer... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2137995" -OutFile "$env:TEMP\WindowsConfigurationDesignerSetup.exe"
    Start-Process "$env:TEMP\WindowsConfigurationDesignerSetup.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\WindowsConfigurationDesignerSetup.exe"
    Write-Host "Windows Configuration Designer has been installed."
}

# Function to install Group Policy Management Console (GPMC)
function Install-GPMC {
    Write-Host "Installing Group Policy Management Console (GPMC)... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=2137752" -OutFile "$env:TEMP\GPMCSetup.msi"
    Start-Process msiexec.exe -ArgumentList "/i $env:TEMP\GPMCSetup.msi /quiet" -Wait
    Remove-Item "$env:TEMP\GPMCSetup.msi"
    Write-Host "Group Policy Management Console has been installed."
}

# Function to install Windows Management Instrumentation (WMI)
function Install-WMI {
    Write-Host "Installing Windows Management Instrumentation (WMI)... "
    Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=2059967" -OutFile "$env:TEMP\WMIInstall.exe"
    Start-Process "$env:TEMP\WMIInstall.exe" -ArgumentList "/q" -Wait
    Remove-Item "$env:TEMP\WMIInstall.exe"
    Write-Host "Windows Management Instrumentation has been installed."
}

# Function to backup registry keys
function Backup-RegistryKeys {
    Write-Host "Backup Selected Registry Keys..."
    $regPaths = @(
        "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion"
        "HKLM\SYSTEM\CurrentControlSet\Services\"
        "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        "HKCU\Software\Microsoft\Windows\CurrentVersion"
        "HKCU\Software\Classes"
    )
    $timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
    $backupPath = "$env:TEMP\RegistryBackup_$timestamp.zip"
    Compress-Archive -Path $regPaths -DestinationPath $backupPath -Force
    Write-Host "Registry keys have been backed up to $backupPath."
}

# Function to restore registry keys
function Restore-RegistryKeys {
    Write-Host "Restore Selected Registry Keys..."
    $backupPath = Read-Host "Enter the path to the registry backup file"
    if (-Not (Test-Path $backupPath)) {
        Write-Host "Backup file not found at $backupPath. Exiting..."
        Exit
    }
    Expand-Archive -Path $backupPath -DestinationPath $env:TEMP -Force
    $regFiles = Get-ChildItem -Path $env:TEMP -Filter "*.zip"
    foreach ($regFile in $regFiles) {
        if (-Not (Test-Path $regFile)) {
            Write-Host "File not found: $regFile. Skipping..."
            continue
        }
        Expand-Archive -Path $regFile.FullName -DestinationPath $env:TEMP -Force
        foreach ($regPath in (Get-ChildItem -Path $env:TEMP -Directory)) {
            $regPath.FullName | Set-Content "$env:TEMP\regpath.txt"
            reg load "HKLM\TempRegKey" $regPath.FullName
            reg unreg load "HKLM\TempRegKey" $regPath.FullName
            reg unreg unload "HKLM\TempRegKey"
        }
    }
    Write-Host "Registry keys have been restored."
}

# Main Script Execution
while ($true) {
    Show-Menu
    $choice = Read-Host "Please select an option (1-41Reach maximum context length. Try to use English or/and shorten your requirement.

### Additional information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting triageAwaiting triage from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions