0% found this document useful (0 votes)
25 views1 page

TeamViewer Host Installation Script

This PowerShell script stops the Teamviewer service and client, uninstalls any existing Teamviewer installation, downloads and installs a new Teamviewer host installer from a URL, starts the Teamviewer service and client, and outputs the Teamviewer ID.

Uploaded by

halljps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

TeamViewer Host Installation Script

This PowerShell script stops the Teamviewer service and client, uninstalls any existing Teamviewer installation, downloads and installs a new Teamviewer host installer from a URL, starts the Teamviewer service and client, and outputs the Teamviewer ID.

Uploaded by

halljps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

function ServiceExists($ServiceName) { (Get-Service -Name $ServiceName -ErrorAction

SilentlyContinue).Length -gt 0 }

function FileExists($path) { return (Test-Path -Path $path -PathType Leaf -


ErrorAction Continue) }

#stop teamviewer service


Write-Host "Stopping Teamviewer"
$timeout = New-Timespan -Seconds 60
if (ServiceExists "Teamviewer")
{
(stop-service -Name "TeamViewer" -Force -Passthru -ErrorAction
SilentlyContinue).WaitForStatus('Stopped',$timeout)
Start-Sleep -Seconds 2
}

#stop teamviewer client software


stop-process -Name "TeamViewer" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2

#uninstall existing teamviewer installation


Write-Host "Uninstalling existing teamviewer installation"
$TV_Uninstaller = "C:\Program Files (x86)\TeamViewer\uninstall.exe"
$TV2_Uninstaller = "C:\Program Files\TeamViewer\uninstall.exe"
if (Test-Path -Path $TV_Uninstaller -PathType Leaf -ErrorAction Continue)
{
Start-Process $TV_Uninstaller -Wait -ArgumentList '/S', '/norestart'
}
elseif (Test-Path -Path $TV2_Uninstaller -PathType Leaf -ErrorAction Continue)
{
Start-Process $TV2_Uninstaller -Wait -ArgumentList '/S', '/norestart'
}
else { write-error "No uninstaller available for Teamviewer. Terminating" ; exit }

Start-Sleep -Seconds 10

#download new Teamviewer installer and install


Write-Host "Download Teamviewer host installer from blob storage"
$url_64 = "<Insert blob url here>”
$dest_64 = "C:\TeamViewer_Host_Setup.msi"
$args_64 = "/quiet /qn /norestart"
Start-BitsTransfer -Source $url_64 -Destination $dest_64
Start-Sleep -Seconds 10

#install teamviewer
Write-Host "Install new teamviewer host"
if (!(Test-Path -Path $dest_64 -PathType Leaf -ErrorAction Continue)) { write-error
"TV host installer doesnt exist at $dest_64. Terminating." ; exit}
Start-Process $dest_64 -Wait -ArgumentList $args_64

#confirm teamviewer service is running


Write-Host "Status of Teamviewer Service"
(Get-WmiObject win32_service).where{($_.Name -like 'Teamview*')} | format-Table
name, DisplayName, state, startname, startmode

#start Teamviewer client software


Write-Host "Starting Teamviewer Host client"
$TV_EXE_PATH = "C:\Program Files (x86)\TeamViewer\TeamViewer.exe"
$TV_WORK_DIR = "C:\Program Files (x86)\TeamViewer"
Start-Process -FilePath $TV_EXE_PATH -WorkingDirectory $TV_WORK_DIR -WindowStyle
Minimized

Start-Sleep -Seconds 5

#return teamviewer ID
Write-Host "Teamviewer ID as recorded in registry"
Get-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\TeamViewer | Select-Object -
ExpandProperty ClientID

You might also like