Sometime before I have received one crazy request from the team, They want to uninstall 2 plugin apps from the production machine. but the condition is if the machine name ends with letter "D" then only start uninstallation from the machine, else leave the applications as it is.
In the PowerShell script first, we have to determine the computer name and then check if the machine name is ending with the letter D and finally we have to start the uninstallation from the target machine.
so here are 3 requirement block has to write in the script.
in the Uninstallation program name, we have used the uninstallation string from registry - Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
if the application is x64 bit version then we have to collect the uninstallation string from the registry path -Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall.
let's test it and share your feedback.
<#
.SYNOPSIS
Uninstall the application from computer powershell - If computer name ends with latter D
.DESCRIPTION
Run This script with the below parameters
powershell.exe -windowstyle hidden -executionpolicy bypass -file uninstallapp.ps1
.NOTES
=============================================================================================================================================
Created with: Windows PowerShell ISE
Created on: Tuesday, August 17, 2021 2:05:44 PM
Created by: Dashrath Chate
Organization: ING
=============================================================================================================================================
#>
Add-Type -AssemblyName PresentationFramework
$lastoneCharsOfComputerName = $ENV:COMPUTERNAME.Substring($ENV:COMPUTERNAME.Length - 1)
if($lastoneCharsOfComputerName -eq "D")
{
start-process "msiexec.exe" -arg "/X{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00} /q" -Wait
start-process "msiexec.exe" -arg "/X{880A6496-9E39-48FD-A4EF-540173E4C1ED} /q" -Wait
}
else
{}
No comments:
Post a Comment
Leave your valuable words here for improve better.