$TeamViewerVersions = @('6','7','8','9','')

If([IntPtr]::Size -eq 4) {
    $RegPath='HKLM:\SOFTWARE\TeamViewer'    
} else {
    $RegPath='HKLM:\SOFTWARE\Wow6432Node\TeamViewer'
}

$ErrorActionPreference= 'silentlycontinue'

foreach ($TeamViewerVersion in $TeamViewerVersions) {
    If ((Get-Item -Path $RegPath$TeamViewerVersion).GetValue('ClientID') -ne $null) {
        $TeamViewerID=(Get-Item -Path $RegPath$TeamViewerVersion).GetValue('ClientID')
    }
}

Write-Host "$TeamViewerID"