teamviewer.com link icon
or
Ask The Community

TeamViewer is one of the winners of the European Customer Centricity Award 🥳


Please find more information here.

Troubleshooting Assignment tool

I'm writing a powershell install wrapper for TeamViewer 12 to push over SCCM. Host is installing fine and pulling the correct configuration/policy. However, the assignment tool is failing.

The documentation--sparse as it is--is very vague with exit codes. Essentially it says 1 means 'an error occurred'. Thanks for that, it's really helpful *sarcasm*. The documentation says nothing of an exit code of 2, which is what I'm getting from my script. Here's a code snippet:

If (Test-Path ${InstallDir}\AssignmentData.json)
{
Copy-Item -Path "{$Target}\TeamViewer_Assignment.exe" -Destination "${InstallDir}\TeamViewer_Assignment.exe" -Force
$AssignArgs = "-datafile AssignmentData.json -apitoken ${Token} -devicealias ${env:COMPUTERNAME} -allowEasyAcces=true -verbose"
$Assign = Start-Process ${InstallDir}\TeamViewer_Assignment.exe -Argumentlist $AssignArgs -WindowStyle Hidden -PassThru
Wait-Process -InputObject $Assign
}
If ($Assign.ExitCode -ne 0)
{
If ($Assign.ExitCode -eq $NULL)
{
Write-Warning "Assignment tool did not start successfully!"
}
Else
{
Write-Warning "Assignment tool terminated with status code $($Assign.ExitCode)."
}
}
ElseIf ($Assign.ExitCode -eq 0)
{
New-Item -ItemType File -Path "${InstallDir}\12_Assign.dep"
If (Test-Path ${InstallDir}\12_Assign.dep)
{
Write-Host "${TV} was assigned to company account associated with ${ConfID}." -ForegroundColor Cyan
}
}

I'm not familiar with best practices for scripting TeamViewer's processes, but this methodology works for the MSI installer (full fat and host) when retrieving exit codes is critical to automating the deployment. Does the assignment tool handle arguments differently? What does exit code 2 signify? I can't get the thing to spit out a log.

Best Answer

Answers

  • Mods, can you move this to API/Scripting; probably more relevant to this. Sorry!

  • amoeller
    amoeller Posts: 2

    I am running into a simlar issue with my powershell installer. After i install the MSI host file with our conten id on the end of the file, and the .reg file gets **bleep** in automatically when installing I trying to apply the assigment tool to my install. I keep getting error code 1 back, which i am guessing is that it cant find the .json file. I cant figure out what i am doing wrong with the PS command.

    [int]$Task = (Start-Process -FilePath "$CurrentDirectory\TeamViewer_Assignment.exe" -ArgumentList ("-apitoken 123456789xxxxxyz -datafile ${Env:ProgramFiles(x86)}\TeamViewer\AssignmentData.json -allowEasyAccess=true") -PassThru -Wait).ExitCode

    Is there something i am missing, I have even try not using the Env varible but still get the same thing. I have also try to replace the token and file path with $Token & $JSON, so I could feed the information from up top.

    EDIT: API token edited by moderator

  • bferg317
    bferg317 Posts: 8

    Wrap your code in tags so it's not a jumbled mess. You're missing a closing ')' for starters, paste exactly what you're using in code tags. Also REMOVE YOUR API TOKEN when you post here. In fact, since you've already posted it, I'd highly encourage you start over with a new one.

    We've since switched to Bomgar due to all the problems and general not-enterprise-worthy status of TV; but I'll take a stab at helping you.

    Here's one of the remediation packages I have built in PDQ; I use this to re-try assigment if it fails somehow. Imporant that you make sure the machine you're trying to assign is not visible in your 'contacts' list. This is meant to be as simple as possible, and spit out a transcript that is equally simple; making it easier for non experienced team members to work with. Ignore the Write-Host lines, these are part of the deployment script, I just cut out a portion of it to base this off of. You also don't need the line regarding 12_host.eval, this is just part of the file-based detection method I'm using SCCM as a double check.

    If you want my full install script, I can send it to you, just PM me.

    $TV = "TeamViewer"
    $Source = "\\REDACTED\TeamViewer\12\"
    $Target = "C:\WINDOWS\CCMCACHE\TeamViewer\12"
    $InstallDir = "${env:ProgramFiles(x86)}\TeamViewer"
    $Stamp = (Get-Date -Format yyy-mm-dd-hh-mm)
    $Token = "REDACTED"
    $ConfID = "REDACTED"
    $Keys = @(
    "HKLM:\SOFTWARE\TeamViewer",
    "HKLM:\SOFTWARE\WOW6432Node\TeamViewer",
    "HKU:\.DEFAULT\Software\Wow6432Node\TeamViewer",
    "HKU:\.DEFAULT\Software\TeamViewer",
    "HKCU:\Software\TeamViewer"
    )
    Write-Host "+Assign" -ForegroundColor Gray
    Copy-Item -Path "\\REDACTED\TeamViewer\12\Host\TeamViewer_Assignment.exe" -Destination "${InstallDir}\TeamViewer_Assignment.exe" -Force
    Start-Sleep -s 5
    If ((Test-Path ${InstallDir}\AssignmentData.json) -and (Test-Path ${InstallDir}\TeamViewer_Assignment.exe))
    {
    Invoke-Expression "& 'C:\Program Files (x86)\TeamViewer\TeamViewer_Assignment.exe' -apitoken REDACTED -datafile 'C:\Program Files (x86)\TeamViewer\AssignmentData.json' -allowEasyAccess=true -verbose >>C:\TeamViewer\AssignPS.log"
    # CAN WE TALK ABOUT HOW ANNOYING IT IS TO CAPTURE CMD OUTPUT INTO POWERSHELL? SALTMACHINE.JPG
    }
    If ($LASTEXITCODE -ne 0)
    {
    If ($LASTEXITCODE -eq $NULL)
    {
    Write-Warning "Assignment tool did not start successfully!"
    }
    Else
    {
    Write-Warning "Assignment tool terminated with status code $($LASTEXITCODE)."
    }
    }
    ElseIf ($LASTEXITCODE -eq 0)
    {
    New-Item -ItemType File -Path "${InstallDir}\12_Assign.eval" # See below
    If (Test-Path ${InstallDir}\12_Assign.eval)
    {
    Write-Host "${TV} was assigned to corporate account associated with ${ConfID}." -ForegroundColor Cyan
    }
    }
    Else
    {
    Write-Warning "An unknown exception occurred."
    }
    Write-Host "-Assign" -ForegroundColor Gray

     The log it spits out looks like this:

    TeamViewer_Assignment (r345)
    Expanded 'datafile'-Parameter : C:\Program Files (x86)\TeamViewer\AssignmentData.json
    Expanded 'devicealias'-Parameter : 
    2018-01-30 11:09:06 WebAPI: GET 'devices?remotecontrol_id='
    2018-01-30 11:09:07 => 200 (Body: {"devices":[]})
    No existing Device found, adding Device to partnerlist
    2018-01-30 11:09:07 WebAPI: GET 'groups?name=New+Deployments&shared=False'
    2018-01-30 11:09:07 => 200 (Body: {"groups":[{"id":"","name":"New Deployments","shared_with":[],"permissions":"owned","policy_id":""}]})
    2018-01-30 11:09:07 WebAPI: POST 'devices' (Body: {"remotecontrol_id":"","groupid":"","alias":""})
    2018-01-30 11:09:09 => 200 (Body: {"remotecontrol_id":"","device_id":"","alias":"","groupid":"","online_state":"Online","assigned_to":false,"supported_features":"remote_control, chat"})
    2018-01-30 11:09:09 WebAPI: POST 'devices/assign' (Body: {"device_id":"","assign_mode":"easyrollout","current_device_password":"","enable_easy_access":true})
    2018-01-30 11:09:14 => 204 (Body: )
    => Assignment finished !

    I trimmed a lot of stuff out of that. You'll notice the error codes here are simple HTTP error codes (200 = good) and there are some other helpful notes it will give as well on line 6.

    Play with that and see if you can't figure out what's going on with yours.

  • amoeller
    amoeller Posts: 2

    Thank you for your respones, I was able to figure this out on friday, and what needed to be done. I needed to Run the Assigment tool two times with a sleep of 15 Secs in between it for it  to work every time. I also had to feed the Json's location file path with `"C:\........\AssignmentData.json`" so it could read it. Right now i have it reading the reg file and add the L-key like it should and assigning itself to the account during install.

    Below is the code i used if anyone else wants a powershell script to install TV13.

    # ==============================================================================================
    #
    # NAME: TeamViewer-Installer.ps1
    #
    # AUTHOR: Alec Moeller
    # DATE : 6/08/2018
    #
    # ==============================================================================================

    #Setting the parameters for Autoupdate if it is not specify
    Param ([String] $Full="No", [String] $Agent="No")

    #System Variables
    $ScriptName = [io.path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)
    $CurrentDirectory = split-path -parent $MyInvocation.MyCommand.Path
    $LogDir = "$ENV:SystemDrive\Logs"
    $LogFile = "$LogDir\$scriptname.log"
    $InstallerLog = "TV13.log"
    $ProcessID = [Diagnostics.Process]::GetCurrentProcess().ID
    $ProcessUserName = ((Get-WmiObject -Class Win32_Process | Where-Object {$_.ProcessID -EQ $ProcessID}).GetOwner()).User
    $App = $CurrentDirectory+"\TeamViewer_Assignment.exe"
    $Arg = "-apitoken ###################### -datafile `"C:\Program Files (x86)\TeamViewer\AssignmentData.json`" -allowEasyAccess=true"

    #Functions to log install status
    Function script:Log
    {
    [CmdletBinding()]
    Param ([String]$File,[String]$Data)
    $LogOutput = '<!Logged-->"' + $Data + '"-->Timestamp:"' + (Get-Date -Format MM-dd-yyyy) + '-"' + (Get-Date -Format HH:mm:ss) + '" Ran by:"' + $ProcessUserName + '" ProcessID="' + $ProcessID + '">'
    Out-File -FilePath $file -Append -NoClobber -InputObject $LogOutput -Encoding ASCII
    }

    #Log File Maintenance
    If (Test-Path -Path $LogFile)
    {
    Remove-Item -Path $LogFile
    }
    If (Test-Path $LogDir\$InstallerLog)
    {
    Remove-Item $LogDir\$InstallerLog
    }
    log -File $LogFile -Data "Removed old log files for this install"

    if ($Agent -eq "Yes")
    {
    #Remove old Registry Keys before installing upgrade.
    If(Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\TeamViewer")
    {
    Remove-Item -Path HKCU:\SOFTWARE\TeamViewer -Force -Recurse
    Remove-Item -Path HKLM:\SOFTWARE\TeamViewer -Force -Recurse
    Remove-Item -Path HKLM:\SOFTWARE\Wow6432Node\TeamViewer -Force -Recurse
    }

    #Installing Teamviewer Host
    log -File $LogFile -Data "TeamViewer Host is now starting to install on the system."
    [int]$Task = (Start-Process -FilePath 'msiexec' -ArgumentList "/i ""$($CurrentDirectory + '\TeamViewer_Host-idcz63wyea.msi')"" /qn /lv C:\Logs\TVHost.log" -PassThru -Wait).ExitCode

    #Evaulating the return to see if the installer was successful
    If ($Task -ne 0)
    {
    log -File $LogFile -Data "TeamViewer Host did not install correctly with error code: $Task"
    [System.environment]::Exit($Task)
    }
    else
    {
    log -File $LogFile -Data "TeamViewer Host just succsefully installed with a return code of $Task"
    Remove-Item "C:\Users\Public\Desktop\TeamView*.lnk" -Force -Recurse
    }

    #Using the Assigment Tool, need to run it two times for it to work.
    log -File $LogFile -Data "Assigment tool is now assiging the host to Ellsworth group"
    Start-Sleep -Seconds 15
    [int]$Task = (Start-Process -FilePath "$APP" -ArgumentList $Arg -PassThru -Wait -NoNewWindow).ExitCode
    Start-Sleep -Seconds 15
    [int]$Task = (Start-Process -FilePath "$APP" -ArgumentList $Arg -PassThru -Wait -NoNewWindow).ExitCode

    #Evaulating the return to see if the Assigment Tool was successful
    If ($Task -ne 0)
    {
    log -File $LogFile -Data "TeamViewer Assigment Tool did not run correctly with error code: $Task"
    #[System.environment]::Exit($Task)
    }
    else
    {
    log -File $LogFile -Data "TeamViewer Assigment Tool was succsefully with a return code of $Task"
    }
    }

    #Install full version
    if ($Full -eq "Yes")
    {
    log -File $LogFile -Data "TeamViewer Host is now starting to install on the system."
    [int]$Task = (Start-Process -FilePath 'msiexec' -ArgumentList "/i ""$($CurrentDirectory + '\TeamViewer_Full-idcz63wyea.msi')"" /qn /lv C:\Logs\TVFull.log" -PassThru -Wait).ExitCode

    #Evaulating the return to see if the installer was successful
    If ($Task -ne 0)
    {
    log -File $LogFile -Data "TeamViewer Full did not install correctly with error code: $Task"
    [System.environment]::Exit($Task)
    }
    else
    {
    log -File $LogFile -Data "TeamViewer Full just succsefully installed with a return code of $Task"
    }
    }

    Sorry for the Emoji face at the top, hope this helps others out.

  • can you share the full install script for TEAMVIEWER.  Thanks, my email: [Edit by moderator per TeamViewer guidline]