Tìm kiếm ↓↓↓

Hướng dẫn tạo Powershell Script gỡ bỏ cài đặt của phần mềm đã cài trong Windows

Nếu bạn muốn gỡ bỏ nhanh một phần mềm đã được cài đặt trong Windows, bạn có thể tạo trước tập tin Powershell Script trong đó được lưu những kịch bản được tạo trước và cho phép lựa chọn phần mềm muốn gỡ. Các bước thực hiên như sau:

1. Tạo Powershell Script lấy danh sách phần mềm đã được cài đặt trong Windows

Trường hợp bạn chỉ muốn xem danh sách của những phần mềm đã được cài đặt bạn có thể soạn nội dung như sau:

Soạn nội dung bên dưới vào notepad và lưu lại với tên ví dụ Get-InstalledSoftwares.ps1 định dạng All files và Econding-ANSI


# Get-Installedsoftwares.ps1

# Created by Nguyen Tuan

# Website:  www.blogthuthuatwin10.com



If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {



Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $args" -Verb RunAs



Exit



}



Function Main-menu()



{

$index=1

    $items = @(


        "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"

        "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"

    )


$softwares=Get-ItemProperty $items

#return entire listing of softwares

   Write-Host "ID`t Installed software"

        echo ""

foreach ($software in $softwares)

{

Write-Host " $index`t $($software.displayname)"

        $index++

    }

    if ($softwares)

    {

$index++

        echo ""

        pause

}

    else

    {

        Write-Host "Software not found"

        echo ""

        pause

    }

}


Main-menu


Khi tạo xong chuột phải tập tin script vừa tạo chọn Run with Powershell


2. Gỡ bỏ cài đặt phần mềm

Trường hợp nếu bạn muốn kết hợp cả việc gỡ bỏ cài đặt của phần mềm đã cài thì soạn nội dung như sau:

Soạn nội dung bên dưới vào notepad và lưu lại với tên ví dụ Remove-InstalledSoftwares.ps1 định dạng All files và Econding-ANSI


# Remove-Installedsoftwares.ps1

# Created by Nguyen Tuan

# Website:  www.blogthuthuatwin10.com



If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {

Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $args" -Verb RunAs

Exit

}



Function Main-menu()

{

    $index=1

    $items = @(

        "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"

        "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"

    )

$softwares=Get-ItemProperty $items

#return entire listing of softwares

   Write-Host "ID`t Installed software"

        echo ""

foreach ($software in $softwares)

{

Write-Host " $index`t $($software.displayname)"

        $index++

    }

    if ($softwares)

    {

$index++

        echo ""

}

    else

    {

        Write-Host "Software not found"

        echo ""

        pause

        exit

    }

        Do

        {

   echo ""

            $IDs=Read-Host -Prompt "Select ID and press Enter"

        }

        While($IDs -eq "")

   

   #check whether input values are correct

   try

   {

[int[]]$IDs=$IDs -split ","

   }

   catch

   {

Write-Host "Error:" $_.Exception.Message

   }



   foreach ($ID in $IDs)

   {

#check id is in the range

   if ($ID -ge 1 -and $ID -le $softwares.count)

   {

$ID--

#Remove each app

$software=$softwares[$ID].UninstallString



echo ""

            echo "Uninstalling software...."

            Start-Process cmd -ArgumentList "/c ""$software""" -NoNewWindow -Wait

            cls      

            echo "Software has been uninstalled successfully"

            echo ""

            pause

            cls

            Main-menu

   }

   else

   {

echo ""

            Write-warning -Message "wrong ID"

            echo ""

            pause

            cls

            Main-menu

   }

        }

}

Main-menu


Khi tạo xong chuột phải tập tin script vừa tạo chọn Run with Powershell


Nếu muốn gỡ bỏ cài đặt của phần mềm nào chọn ID của phần mềm nhấn Enter.

Phổ biến trong tuần

Tin Tức