<# .Synopsis Detects, downloads, installs and configures the latest version of TeamViewer. .Notes Requires TeamViewer 14. TeamViewer Installation Documentation https://community.teamviewer.com/t5/Knowledge-Base/Mass-deployment-improvements/ta-p/39639 #> $ConfigurationID = "64uyck9" $ApiToken = "6615740-y9LI6bdNq5QtaDtiGVTN" $ComputerName = $ENV:COMPUTERNAME if (Test-Path 'C:\Program Files (x86)\TeamViewer\TeamViewer.exe') { Write-Host 'Team Viewer already installed.' return } Write-Host 'Installing TeamViewer.' Write-Host 'Downloading TeamViewer Host Setup.' $SetupFilePath = Join-Path $ENV:TEMP "TeamViewer_Host_Setup-idc$($ConfigurationID).exe" $response = Invoke-RestMethod "https://get.teamviewer.com/$ConfigurationID" $json = '{}' if ($response -match 'configId = "(?[^"]+).*\n.*version = "(?[^"]+).*\n.*isCustomModule = (?[^"]+);.*\n.*subdomain = "(?[^"]+)(?)' ) { $Matches.Remove(0) $Matches['IsCustomModule'] = if ($Matches['IsCustomModule'] -eq 'true') { $true } else { $false } $json = [PsCustomObject]$Matches | ConvertTo-Json } else { throw 'Expected JSON values not found in initial HTML page' } $DownloadUri = Invoke-RestMethod -Uri 'https://get.teamviewer.com/api/CustomDesign' -Method Post -Body $json -ContentType 'application/json' Invoke-WebRequest -Uri $DownloadUri -OutFile $SetupFilePath if (-not (Test-Path $SetupFilePath)) { throw 'TeamViewer_Setup.exe failed to download.' } Write-Host 'Installing.' & $SetupFilePath /S | Write-Output Write-Debug "$SetupFilePath LastExitCode = $LASTEXITCODE" Write-Host 'Configuring' & "C:\Program Files (x86)\TeamViewer\TeamViewer.exe" assign --api-token $ApiToken --grant-easy-access --reassign --alias $ComputerName | Write-Output Write-Debug "TeamViewer.exe assign LastExitCode = $LASTEXITCODE" Write-Host 'Cleaning up.' $SetupTempFolder = Join-Path $ENV:TEMP 'TeamViewer' $SetupFilePath, $SetupTempFolder | Remove-Item -Recurse Write-Host 'Complete.'