Skip to content

Instantly share code, notes, and snippets.

@rhymeswithmogul
Created November 7, 2019 23:26
Show Gist options
  • Save rhymeswithmogul/0f68cbebef68431eac4ebe9df31092b1 to your computer and use it in GitHub Desktop.
Save rhymeswithmogul/0f68cbebef68431eac4ebe9df31092b1 to your computer and use it in GitHub Desktop.
Remove TeamViewer remotely
<#
Remove-TeamViewerRemotely.ps1, version 1.0
-- a quick and dirty script that I wish weren't needed, but here we are.
by Colin Cogle <colin@colincogle.name>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
#>
#
# Edit this variable, and nothing else.
#
$ComputersToRemoveTeamViewerFrom = @(
"Computer01",
"Computer02",
"Computer03"
)
$ComputersToRemoveTeamViewerFrom | ForEach-Object {
# Start a remote PowerShell session on the computer.
Invoke-Command -ComputerName $_ -ScriptBlock `
{
# Find all apps installed on this machine.
$AllApps = Get-ItemProperty "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
# Find the one named TeamViewer.
$TeamViewer = $AllApps | Where-Object {$_.DisplayName -Like "TeamViewer*"}
# When you install an app, the uninstall information is saved in the registry.
# TeamViewer's is just an .exe, so run it, with a hidden window, and the /S (silent) switch.
Start-Process -FilePath ($TeamViewer.UninstallString) -ArgumentList "/S" -WindowStyle Hidden
# Once you do this, NinjaRMM will eventually notice that TeamViewer
# is missing, and it will reinstall and resync it.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment