Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Create and run a Powershell script from SCCM to uninstall the software

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Recently encountered a demand: uninstall a small software for all computers, but this software is not deployed by SCCM, some are installed by users, some are packaged when the system is deployed, there are many versions, and the installation path is not the same!

Of course, the first thing that comes to mind is to use Powershell to do it. I tested it successively with Get-apppacke\ get-appxpacke, Get-WmiObject-Class win32_product and other methods, and finally solved it by looking for the UninstallString in the registry!

The methods are as follows:

1. Navigate to the registry location using PowerShell

X86 Script:

Set-Location HKLM:\ software\ microsoft\ Windows\ Currentversion\ uninstall

X64 Script:

Set-Location HKLM:\ software\ WOW6432Node\ microsoft\ Windows\ Currentversion\ uninstall

2. Query the name of the installed software in the registry Uninstall, such as Chrome. The Childitem in Uninstall is: Google Chrome, where Uninstallstring has the specific path of the uninstalled file, this file name and parameters:

"C:\ Program Files (x86)\ Google\ Chrome\ Application\ 74.0.3729.131\ Installer\ setup.exe"-uninstall-- system-level-- verbose-logging

This is the uninstall command we want to run. Some software only have execution files without parameters. For example, if Teamviewer has only one Uninstall.exe, we can use Uninstall.exe / S to silently uninstall it!

3. The complete PS script is as follows:

Set-Location

HKLM:\ software\ WOW6432Node\ microsoft\ Windows\ Currentversion\ uninstall

# specify the location of the registry

$UninstallTeamviewer = get-childitem-path * Teamviewer* | get-itemproperty |% {$_ .Uninstallstring}

# find the uninstall command and assign it to the variable: $UninstallTeamviewer

Start $UninstallTeamviewer / S

# run uninstall command in Powershell: $UninstallTeamviewer

For those who already have uninstall programs and parameters in the registry, there is no need to add the number of parameters: "/ S"

4. Create a script: right-click in SoftWare Library\ Overview\ Scripts and Create Script:

5. Paste the PowerShell script to the script. Next, finish!

TeamViewer

$OS = (Get-WmiObject Win32_OperatingSystem) .OSArchitecture

# check the operating system version

If ((gwmi win32_operatingsystem | select osarchitecture) .osarchitecture-eq "32-bit") {

# 32 Bit run the following steps

Set-Location HKLM:\ software\ microsoft\ Windows\ Currentversion\ uninstall

# specify the following registry location

$UninstallTeamviewer = get-childitem-path * Teamviewer* | get-itemproperty |% {$_ .Uninstallstring}

# find the uninstall command and assign it to the variable: $UninstallTeamviewer

Start $UninstallTeamviewer / S

# run uninstall command in Powershell: $UninstallTeamviewer

$UninstallTeamviewer

# output variable results to facilitate query and analysis

}

Else {

# 64 Bit run the following steps

Set-Location HKLM:\ software\ WOW6432Node\ microsoft\ Windows\ Currentversion\ uninstall

# specify the following registry location

$UninstallTeamviewer = get-childitem-path * Teamviewer* | get-itemproperty |% {$_ .Uninstallstring}

# find the uninstall command and assign it to the variable: $UninstallTeamviewer

Start $UninstallTeamviewer / S

# run uninstall command in Powershell: $UninstallTeamviewer

$UninstallTeamViewer

# output variable results to facilitate query and analysis

}

6. Approve the script: right-click on the script you just created and approve

In a production environment, user-created scripts need to be approved by a second person for security (that is, they cannot approve their own scripts). If you want to approve your own created scripts, please go to: Administration\ Site Configuration\ Sites\ Hierarchy Settings

Uncheck the box in front of "Script authors require additional script approver".

7. Run the script: right-click on the computer or set you want to run, and select: Run Script\ Next, that is, to start running.

8. You can also view the summary results of running scripts in Monitoring, and in the script status list, you can view the results of each script running on the client device. A script exit code of "0" usually indicates that the script has run successfully.

9. You can also inquire in the software report later!

10. If a software is installed using a MIS package, and the uninstall value will be "MsiExec.exe / I {23170F69-40C1-2701-1602-000001000000}", it is necessary to change to another PowerShell method, for example:

If ((gwmi win32_operatingsystem | select osarchitecture) .osarchitecture-eq "32-bit") {

# 32 Bit 7zip X32 1602 {23170F69-40C1-2701-1602-000001000000}

$script = {invoke-expression "msiexec / qn / x'{23170F69-40C1-2701-1602-00000000000}'"}

Invoke-Command-ScriptBlock $script

$script

} else {

# 64 Bit 7zip X64 1602 {23170F69-40C1-2702-1602-000001000000}

$script = {invoke-expression "msiexec / qn / x'{23170F69-40C1-2702-1602-00000000000}'"}

Invoke-Command-ScriptBlock $script

$script

}

Of course, if you don't have a SCCM environment, you can also try calling the above script in AD!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report