Ticker

6/recent/ticker-posts

Header Ads Widget

Debloat Windows 11 With Powershell

Windows 10/11 pe pre-installed aur unwanted app packages ko manage karna ek mushkil kaam ho sakta hai. Ye packages, jise hum "bloatware" kehte hain, valuable system resources consume karte hain aur user interface ko clutter kar dete hain. Windows kuch tools provide karta hai in packages ko manage karne ke liye, par ye process PowerShell script se aur bhi easy ho sakta hai.

Is article mein di gayi PowerShell script ek simple aur effective method offer karti hai AppX packages ko uninstall karne ka, including those jo Windows ke sath pre-installed hote hain. Ye script unwanted packages ko identify, list aur remove karne ka process automate karti hai, jisse users apne systems ko declutter kar sakein.

Ye script kuch straightforward steps mein kaam karti hai:

Ye saare installed AppX packages ko list karti hai. Ye user ko prompt karti hai ki wo uninstall karne wale packages ki ek list banaye. Ye is list se package names ko read karti hai aur har ek ko uninstall karne ki koshish karti hai. Ye feedback deti hai kisi bhi package ke baare mein jo found nahi ho paya ya uninstall nahi ho paya. Ye guide aapko script ke through walk-through karega, har step ko detail mein explain karega, taaki aap ise effectively use kar sakein aur apne Windows 10/11 system se unwanted app packages ko manage aur remove kar sakein.

Maine apko puri script ka detailed breakdown niche diya hai ap ise copy karke apne kaam mein bhi le sakte hai aur ise samajh bhi sakte hai. Is Script ka use apko kaise karna hai iska detail mein demonstration humne video ke madhayam se bhi diya hai jise ap dekh sakte hai.

Get-AppxPackage | Select Name, PackageFullName | Out-Host

Write-Host "Please create a text file called debloatlist.txt, then copy the names of the packages you want to uninstall into it, one per line."
Write-Host "NOTE: Some of the packages listed above are important. Do not uninstall any packages if you're unsure about their function!"
Write-Host ""
Write-Host "Then press any key to continue ..."
Read-Host


if (-not (Test-Path -Path 'debloatlist.txt')) {
    Write-Host "Error: debloatlist.txt not found. Please create it in the same directory as this script, and add the packages you want to uninstall."
    return
}


$lines = Get-Content -Path 'debloatlist.txt'


$notFound = @()


foreach ($line in $lines) {

    $line = $line.Trim()


    if (-not [string]::IsNullOrWhiteSpace($line)) {

        $package = Get-AppxPackage | Where-Object { $_.Name -eq $line -or $_.PackageFullName -eq $line }
		

        if ($package) {

            try {
                $package | Remove-AppxPackage -ErrorAction Stop
            } 
            catch {
                Write-Host "Error while trying to uninstall $($line): $_"
                $notFound += $line
            }
        } 
        else {
            $notFound += $line
        }
    }
}


if ($notFound) {
    Write-Host "[!!!] WARNING: The following packages were not found and could not be uninstalled:"
    Write-Host ""


    foreach ($package in $notFound) {
        Write-Host "`t$package"
    }
    Write-Host ""
    Write-Host "Please re-check the names to ensure they exactly match a package's 'Name' or 'PackageFullName'."
    Write-Host "(Also check if the Full Name was truncated with '...', and if so try the shorter 'Name' string.)"
    Write-Host ""
}

Explanation of Script 

1. List Installed Appx Packages
Get-AppxPackage | Select Name, PackageFullName | Out-Host

This command retrieves all installed AppX packages on the system and displays their Name and PackageFullName properties. 

2. Prompt User to Create debloatlist.txt:
Write-Host "Please create a text file called debloatlist.txt, then copy the names of the packages you want to uninstall into it, one per line."
Write-Host "NOTE: Some of the packages listed above are important. Do not uninstall any packages if you're unsure about their function!"
Write-Host ""
Write-Host "Then press any key to continue ..."
Read-Host

This section of the script displays instructions to the user, asking them to create a text file named debloatlist.txt and populate it with the names of the packages they wish to uninstall, one per line. The script then pauses and waits for the user to press a key to continue. 

3. Check for debloatlist.txt:
if (-not (Test-Path -Path 'debloatlist.txt')) {
    Write-Host "Error: debloatlist.txt not found. Please create it in the same directory as this script, and add the packages you want to uninstall."
    return
}

The script checks if debloatlist.txt exists in the same directory. If the file is not found, it displays an error message and stops execution. 

 4. Read Package Names from debloatlist.txt:
$lines = Get-Content -Path 'debloatlist.txt'
This line reads the contents of debloatlist.txt into an array called $lines, where each element is a line from the file. 


5. Initialize Array for Unsuccessful Attempts:
$notFound = @()

6. Process Each Line in debloatlist.txt:
foreach ($line in $lines) {
    $line = $line.Trim()
    if (-not [string]::IsNullOrWhiteSpace($line)) {
        $package = Get-AppxPackage | Where-Object { $_.Name -eq $line -or $_.PackageFullName -eq $line }
        if ($package) {
            try {
                $package | Remove-AppxPackage -ErrorAction Stop
            } 
            catch {
                Write-Host "Error while trying to uninstall $($line): $_"
                $notFound += $line
            }
        } 
        else {
            $notFound += $line
        }
    }
}

Trim Whitespace: 
Remove leading and trailing whitespace from the line. 

Ignore Empty Lines: 
Skip lines that are empty or contain only whitespace. 

Find the Package: 
Search for a package that matches the name or full package name. 

Uninstall the Package: 
If the package is found, attempt to uninstall it. If an error occurs during uninstallation, catch the error, display a message, and add the package name to the $notFound array. 

Track Not Found Packages: If the package is not found, add the name to the $notFound array. 


 7. Report Unsuccessful Uninstallations:
if ($notFound) {
    Write-Host "[!!!] WARNING: The following packages were not found and could not be uninstalled:"
    Write-Host ""
    foreach ($package in $notFound) {
        Write-Host "`t$package"
    }
    Write-Host ""
    Write-Host "Please re-check the names to ensure they exactly match a package's 'Name' or 'PackageFullName'."
    Write-Host "(Also check if the Full Name was truncated with '...', and if so try the shorter 'Name' string.)"
    Write-Host ""
}
If there were any packages that could not be found or uninstalled, the script displays a warning message listing those packages. It advises the user to check the names for exact matches and to be aware of potential truncations in package names.


Watch Video for Step by Step Process


एक टिप्पणी भेजें

0 टिप्पणियाँ