To install or repair TeamViewer Host using PowerShell, including compatibility with remote PowerShell, run the lines below, and don't forget to set your token:
# 0. FIRST STEP - SET YOUR TOKEN!!
$tvToken = <INSERT YOUR TEAMVIEWER ASSIGNMENT TOKEN>
# 1. Stop Services and Processes to release file locks
Write-Host "Stopping existing TeamViewer processes..."
Stop-Service -Name "TeamViewer" -Force -ErrorAction SilentlyContinue
Stop-Process -Name "TeamViewer" -Force -ErrorAction SilentlyContinue
Stop-Process -Name "TeamViewer_Service" -Force -ErrorAction SilentlyContinue
sc.exe delete TeamViewer
# 2. Silently Uninstall Existing Versions (Full or Host, 32-bit or 64-bit)
Write-Host "Hunting for existing TeamViewer uninstallers..."
$uninstallPaths = @(
"$env:ProgramW6432\TeamViewer\uninstall.exe",
"${env:ProgramFiles(x86)}\TeamViewer\uninstall.exe"
)
foreach ($path in $uninstallPaths) {
if (Test-Path $path) {
Write-Host "Found uninstaller at: $path. Uninstalling silently..."
# Run uninstaller and wait for it to finish
Start-Process -FilePath $path -ArgumentList "/S" -Wait
}
}
# 3. Give the system a few seconds to release registry keys and files
Start-Sleep -Seconds 5
# 4. Force delete leftover installation folders
Write-Host "Clearing leftover directories..."
Remove-Item -Path "$env:ProgramW6432\TeamViewer" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "${env:ProgramFiles(x86)}\TeamViewer" -Recurse -Force -ErrorAction SilentlyContinue
# 5. Download the Latest Version
$url = "https://download.teamviewer.com/download/TeamViewer_Host_Setup.exe"
$outputPath = "C:\TeamViewer_Host_Setup.exe"
Write-Host "Downloading latest TeamViewer Host..."
Invoke-WebRequest -Uri $url -OutFile $outputPath
Write-Host "Download Complete."
# 6. Install Silently
Write-Host "Installing fresh TeamViewer Host..."
Start-Process -FilePath $outputPath -ArgumentList "/S" -Wait
Write-Host "Installation Complete."
# 7. Assignment
Write-Host "Assigning device to your account..."
Start-Sleep -Seconds 10
# Note: TeamViewer usually installs to Program Files on modern 64-bit systems, but defaults to x86 for 32-bit versions.
# We'll check which one exists before running the assign command.
$tvExe = if (Test-Path "$env:ProgramW6432\TeamViewer\TeamViewer.exe") { "$env:ProgramW6432\TeamViewer\TeamViewer.exe" } else { "${env:ProgramFiles(x86)}\TeamViewer\TeamViewer.exe" }
& $tvExe assign --token $tvToken --grant-easy-access
# 8. Remove Installer
Remove-Item -Path $outputPath -Force
Write-Host "Installer deleted. Setup is fully complete!"
# 9. Check for the ID in both standard and 64-bit registry locations
$tvRegPath32 = "HKLM:\SOFTWARE\WOW6432Node\TeamViewer"
$tvRegPath64 = "HKLM:\SOFTWARE\TeamViewer"
if (Test-Path $tvRegPath32) {
$tvID = (Get-ItemProperty -Path $tvRegPath32).ClientID
} elseif (Test-Path $tvRegPath64) {
$tvID = (Get-ItemProperty -Path $tvRegPath64).ClientID
}
Write-Host "TeamViewer ID: $tvID"Done!