Table of Contents
Purpose of the Script
- Automatically download and install the latest version of TeamViewer.
- Uses Microsoft’s Winget GitHub. repository to locate the official installer.
- Performs a silent installation for all users.
# Define the GitHub API URL for the app manifests in winget-pkgs.
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer"
# Fetch version folders then filter only version folders.
$header = @{ "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" }
$versions = Invoke-RestMethod -Uri $apiUrl -Headers $header
$versionFolders = $versions | Where-Object { $_.type -eq "dir" }
# Extract and sort version numbers to get the latest version.
$sortedVersions = $versionFolders | ForEach-Object { $_.name } | Sort-Object {[version]$_} -Descending -ErrorAction SilentlyContinue
$latestVersion = $sortedVersions[0]
Write-Host "Latest TeamViewer version: $latestVersion."
# Get contents of the latest version folder to find the .installer.yaml file.
$latestApiUrl = "$apiUrl/$latestVersion"
$latestFiles = Invoke-RestMethod -Uri $latestApiUrl -Headers $header
$installerFile = $latestFiles | Where-Object { $_.Name -like "*.installer.yaml" }
# Download and parse YAML content to get the Url of the latest installer file.
$yamlUrl = $installerFile.download_url
$yamlContent = Invoke-RestMethod -Uri $yamlUrl -Headers $header
$yamlString = $yamlContent -join "`n"
$installerUrls = [regex]::Matches($yamlString, "InstallerUrl:\s+(http[^\s]+)") | ForEach-Object { $_.Groups[1].Value }
$installerUrl = $installerUrls[2]
Write-Host "Downloading installer from: $installerUrl"
# Download the latest installer to the temp folder.
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($installerUrl, "$env:TEMP\TeamViewer-latest.zip")
Expand-Archive -Path "$env:TEMP\TeamViewer-latest.zip" -DestinationPath "$env:TEMP\TeamViewer" -Force
# Start the install process.
Set-Location -Path $env:TEMP\TeamViewer
Start-Process -FilePath msiexec.exe -ArgumentList '/i update.msi /qn' -Wait
# Delete the downloaded installer file.
Remove-Item -Path "$env:TEMP\TeamViewer-latest.zip" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:TEMP\TeamViewer" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "TeamViewer installation completed."
Step-by-Step Explanation
Below is a detailed explanation of what each part of the PowerShell script does. The script is designed to automatically install or update TeamViewer on Windows computers.
1. Define the API URL
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer"
- Points to the TeamViewer manifest folder in the winget-pkgs GitHub repository.
- This folder contains subfolders for each version.
2. Get the list of available versions
$header = @{ "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" }
$versions = Invoke-RestMethod -Uri $apiUrl -Headers $header
$versionFolders = $versions | Where-Object { $_.type -eq "dir" }
- Fetches all items in the folder (both files and folders).
- Filters to only include directories, because each directory represents a TeamViewer version.
# Output
PS C:\> $versionFolders
name : 15.59.5
path : manifests/t/TeamViewer/TeamViewer/15.59.5
sha : 4a1d449f0200cdda2927be90b61cc082fff9afea
size : 0
url : https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer/15.59.5?re
f=master
html_url : https://github.com/microsoft/winget-pkgs/tree/master/manifests/t/TeamViewer/TeamViewer/15.59.5
git_url : https://api.github.com/repos/microsoft/winget-pkgs/git/trees/4a1d449f0200cdda2927be90b61cc082fff9afea
download_url :
type : dir
_links : @{self=https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer/15.
59.5?ref=master; git=https://api.github.com/repos/microsoft/winget-pkgs/git/trees/4a1d449f0200cdda2927be
90b61cc082fff9afea;
html=https://github.com/microsoft/winget-pkgs/tree/master/manifests/t/TeamViewer/TeamViewer/15.59.5}
...
3. Extract and sort versions
$sortedVersions = $versionFolders | ForEach-Object { $_.name } | Sort-Object {[version]$_} -Descending -ErrorAction SilentlyContinue
$latestVersion = $sortedVersions[0]
- Extracts folder names (version numbers).
- Sorts them as version objects (not strings) in descending order.
- Picks the latest version (first in the sorted list).
# Output
PS C:\> $sortedVersions
15.67.5
15.67.4
15.67.3
15.66.5
15.65.6
15.65.4
15.64.3
15.63.5
15.63.4
...
4. Get the .installer.yaml file for the latest version
$latestApiUrl = "$apiUrl/$latestVersion"
$latestFiles = Invoke-RestMethod -Uri $latestApiUrl -Headers $header
$installerFile = $latestFiles | Where-Object { $_.Name -like "*.installer.yaml" }
- Looks inside the latest version folder.
- Finds the *.installer.yaml file, which contains metadata about the installer (URLs, architecture, etc.).
# Output
PS C:\> $installerFile
name : TeamViewer.TeamViewer.installer.yaml
path : manifests/t/TeamViewer/TeamViewer/15.67.5/TeamViewer.TeamViewer.installer.yaml
sha : 522d02feb03c93dff69c31a729cc7103e773686f
size : 2247
url : https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer/15.67.5/Te
amViewer.TeamViewer.installer.yaml?ref=master
html_url : https://github.com/microsoft/winget-pkgs/blob/master/manifests/t/TeamViewer/TeamViewer/15.67.5/TeamViewe
r.TeamViewer.installer.yaml
git_url : https://api.github.com/repos/microsoft/winget-pkgs/git/blobs/522d02feb03c93dff69c31a729cc7103e773686f
download_url : https://raw.githubusercontent.com/microsoft/winget-pkgs/master/manifests/t/TeamViewer/TeamViewer/15.67.5
/TeamViewer.TeamViewer.installer.yaml
type : file
_links : @{self=https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer/15.
67.5/TeamViewer.TeamViewer.installer.yaml?ref=master; git=https://api.github.com/repos/microsoft/winget-
pkgs/git/blobs/522d02feb03c93dff69c31a729cc7103e773686f; html=https://github.com/microsoft/winget-pkgs/b
lob/master/manifests/t/TeamViewer/TeamViewer/15.67.5/TeamViewer.TeamViewer.installer.yaml}
5. Extract installer URLs from YAML to find the URL of the latest version
$yamlUrl = $installerFile.download_url
$yamlContent = Invoke-RestMethod -Uri $yamlUrl -Headers $header
$yamlString = $yamlContent -join "`n"
$installerUrls = [regex]::Matches($yamlString, "InstallerUrl:\s+(http[^\s]+)") | ForEach-Object { $_.Groups[1].Value }
$installerUrl = $installerUrls[2]
- Downloads the YAML file as raw text.
- Extracts all InstallerUrl entries using regular expressions.
- Picks the URL using an index number.
# Output
$installerUrl
https://download.teamviewer.com/download/version_15x/update/Update_msi_15.67.5_x64.zip
6. Download the installer
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($installerUrl, "$env:TEMP\TeamViewer-latest.zip")
Expand-Archive -Path "$env:TEMP\TeamViewer-latest.zip" -DestinationPath "$env:TEMP\TeamViewer" -Force
- Downloads the installer to the Windows temp folder ($Env:Temp)
7. Install TeamViewer silently
Set-Location -Path $env:TEMP\TeamViewer
Start-Process -FilePath msiexec.exe -ArgumentList '/i update.msi /qn' -Wait
- Runs the installer in silent mode, no user interaction.
8. Clean up the installer and notify to user
Remove-Item -Path "$env:TEMP\TeamViewer-latest.zip" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:TEMP\TeamViewer" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "TeamViewer installation completed."
- Deletes the installer after installation to keep the system clean.
- Outputs a message to confirm the installation status.
How to install using PowerShell
To install the app, simply open PowerShell as an administrator, copy the code snippets below, paste them into the PowerShell window, and press .
# Define the GitHub API URL for the app manifests in winget-pkgs.
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/t/TeamViewer/TeamViewer"
# Fetch version folders then filter only version folders.
$header = @{ "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" }
$versions = Invoke-RestMethod -Uri $apiUrl -Headers $header
$versionFolders = $versions | Where-Object { $_.type -eq "dir" }
# Extract and sort version numbers to get the latest version.
$sortedVersions = $versionFolders | ForEach-Object { $_.name } | Sort-Object {[version]$_} -Descending -ErrorAction SilentlyContinue
$latestVersion = $sortedVersions[0]
Write-Host "Latest TeamViewer version: $latestVersion."
# Get contents of the latest version folder to find the .installer.yaml file.
$latestApiUrl = "$apiUrl/$latestVersion"
$latestFiles = Invoke-RestMethod -Uri $latestApiUrl -Headers $header
$installerFile = $latestFiles | Where-Object { $_.Name -like "*.installer.yaml" }
# Download and parse YAML content to get the Url of the latest installer file.
$yamlUrl = $installerFile.download_url
$yamlContent = Invoke-RestMethod -Uri $yamlUrl -Headers $header
$yamlString = $yamlContent -join "`n"
$installerUrls = [regex]::Matches($yamlString, "InstallerUrl:\s+(http[^\s]+)") | ForEach-Object { $_.Groups[1].Value }
$installerUrl = $installerUrls[2]
Write-Host "Downloading installer from: $installerUrl"
# Download the latest installer to the temp folder.
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($installerUrl, "$env:TEMP\TeamViewer-latest.zip")
Expand-Archive -Path "$env:TEMP\TeamViewer-latest.zip" -DestinationPath "$env:TEMP\TeamViewer" -Force
# Start the install process.
Set-Location -Path $env:TEMP\TeamViewer
Start-Process -FilePath msiexec.exe -ArgumentList '/i update.msi /qn' -Wait
# Delete the downloaded installer file.
Remove-Item -Path "$env:TEMP\TeamViewer-latest.zip" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "$env:TEMP\TeamViewer" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "TeamViewer installation completed."
Installing using a PowerShell script
Alternatively, you can create a PowerShell script using the code snippet above. For instance, I’ve created and save a script at “C:\Scripts\install.ps1″.
Next, open PowerShell (or Terminal) as an administrator and execute the PowerShell script using either the call operator or dot notation.
& "C:\Scripts\install.ps1"
# Output
PS C:\> & "C:\Scripts\install.ps1"
Latest TeamViewer version: 15.67.5.
Downloading installer from: https://download.teamviewer.com/download/version_15x/update/Update_msi_15.67.5_x64.zip
TeamViewer installation completed.
PowerShell execution policy
Root cause: The Windows PowerShell execution policy is designed to block untrusted scripts from impacting your Windows client environment. These policies act as security settings that define the trust level for scripts executed in PowerShell. On client operating systems, the default execution policy is set to Restricted, which stops Windows PowerShell commands and scripts from running.
To fix the issue, adjust the execution policy by running the following command:
Set-ExecutionPolicy RemoteSigned
PS C:\> Set-ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy
might expose you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PS C:\>
PS C:\> Get-ExecutionPolicy
RemoteSigned
Use Cases
- Automated software deployment
- Scheduled automatic updates
- Silent install for non-technical users
- Alternative to winget or manual downloads