Powershell:: Uninstall the application remotely (Get the servers/computer from AD )

Below script to uninstall an application from remote servers (or a number of the remote servers). You can also import the list of computers from a txt file using ($computers = get-content .\computer.txt)

$computers = get-adcomputer -filter ‘OperatingSystem -like “*Windows Server*”‘ -SearchBase “<Server name FQDN”

foreach($comp in $computers){

$computer = $comp.name


$log = Invoke-Command -ComputerName $computer -ScriptBlock {

$application = Get-WmiObject Win32_Product -filter “Name=’Application name'”

$appl = $application.name

Write-host “Removing $app from Server”


} |Out-string

if($error[0].Exception -like “*WinRM cannot complete the operation*”) {$status = “Server not accessible”}

elseif($error[0].Exception -like “*null-valued expression*”) {$status = “Application not present”}

Else {$status = “Appllication removal Success”}

Add-content .\Applicationremoval.log -value “$computer;$status”


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s