Repository navigation
Expand file tree
/
Copy pathStart-TeamViewer.ps1
More file actions
414 lines (323 loc) · 13.9 KB
/
Copy pathStart-TeamViewer.ps1
File metadata and controls
414 lines (323 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
function Start-TeamViewer {
<#
.SYNOPSIS
Startet TeamViewer mit verschiedenen Konfigurationsoptionen und Verbindungsparametern.
.DESCRIPTION
Diese Funktion bietet eine PowerShell-Schnittstelle für die TeamViewer Command Line Interface.
Sie unterstützt alle wichtigen Parameter wie Verbindungs-ID, Passwort, Verbindungsmodus,
Qualitätseinstellungen, Proxy-Konfiguration und verschiedene Dateitypen.
.PARAMETER ExePath
Pfad zur TeamViewer.exe. Standard: "$Env:ProgramFiles\TeamViewer\TeamViewer.exe"
.PARAMETER Minimize
Startet TeamViewer minimiert in der Taskleiste
.PARAMETER ID
Partner-ID für die TeamViewer-Verbindung
.PARAMETER Password
Passwort für die Verbindung (SecureString)
.PARAMETER PasswordB64
Base64-kodiertes Passwort für die Verbindung (SecureString)
.PARAMETER Mode
Verbindungsmodus: 'remoteControl' (Standard), 'fileTransfer', oder 'vpn'
.PARAMETER Quality
Verbindungsqualität: '0' (Auto), '1' (Optimized Speed), '2' (Optimized Quality)
.PARAMETER AccessControl
Zugriffskontrollstufe von 0 (Vollzugriff) bis 9 (Undefiniert)
.PARAMETER NoInstallation
Startet TeamViewer im portablen Modus ohne Installation
.PARAMETER PlayFile
Pfad zu einer TeamViewer Session-Datei (*.tvs) zum Abspielen
.PARAMETER ControlFile
Pfad zu einer TeamViewer Control-Datei (*.tvc) für Verbindungen
.PARAMETER ProxyIP
Proxy-Server im Format 'IP:Port' (z.B. '192.168.1.1:8080')
.PARAMETER ProxyUser
Benutzername für Proxy-Authentifizierung
.PARAMETER ProxyPassword
Passwort für Proxy-Authentifizierung (SecureString) (SecureString)
.PARAMETER SendTo
Array von Dateipfaden zum Senden an einen Partner
.EXAMPLE
Start-TeamViewer -Minimize
Startet TeamViewer minimiert
.EXAMPLE
$securePassword = Read-Host -AsSecureString -Prompt 'TeamViewer-Passwort'
Start-TeamViewer -ID 123456789 -Password $securePassword
Stellt eine Remote Control-Verbindung mit ID und sicherem Passwort her
.EXAMPLE
$securePasswordB64 = Read-Host -AsSecureString -Prompt 'Base64-kodiertes Passwort'
Start-TeamViewer -ID 123456789 -PasswordB64 $securePasswordB64 -Mode vpn -Quality 2
Stellt eine VPN-Verbindung mit Base64-Passwort und hoher Qualität her
.EXAMPLE
Start-TeamViewer -PlayFile "C:\Sessions\backup.tvs"
Spielt eine gespeicherte TeamViewer-Session ab
.EXAMPLE
Start-TeamViewer -SendTo @("C:\file1.txt", "C:\file2.pdf")
Sendet Dateien an einen Partner (Partner-Auswahl wird angezeigt)
.EXAMPLE
$proxyPassword = Read-Host -AsSecureString -Prompt 'Proxy-Passwort'
$teamviewerPassword = Read-Host -AsSecureString -Prompt 'TeamViewer-Passwort'
Start-TeamViewer -ID 123456789 -Password $teamviewerPassword -ProxyIP "192.0.2.10:8080" -ProxyUser "admin" -ProxyPassword $proxyPassword
Verbindung über Proxy-Server mit Authentifizierung
.NOTES
Basiert auf TeamViewer Command Line Parameters:
https://www.teamviewer.com/cs/global/support/knowledge-base/teamviewer-classic/for-developers/command-line-parameters/
Erfordert TeamViewer (Classic) Version 13.2 oder höher für alle Parameter.
.LINK
https://www.teamviewer.com/
#>
[CmdletBinding()]
param(
# Pfad zur TeamViewer.exe
[string] $ExePath = "$Env:ProgramFiles\TeamViewer\TeamViewer.exe",
# TeamViewer minimiert starten
[switch] $Minimize,
# Partner-ID für Verbindung
[string] $ID,
# Passwort für Verbindung (SecureString)
[SecureString] $Password,
# Passwort Base64-kodiert (SecureString)
[SecureString] $PasswordB64,
# Verbindungsmodus
[ValidateSet('fileTransfer', 'vpn', 'remoteControl')]
[string] $Mode = 'remoteControl',
# Verbindungsqualität
[ValidateSet('0', '1', '2')]
[string] $Quality,
# Zugriffskontrolle
[ValidateRange(0, 9)]
[int] $AccessControl,
# Portabler Modus ohne Installation
[switch] $NoInstallation,
# TeamViewer Session-Datei abspielen (*.tvs)
[string] $PlayFile,
# Control-Datei für Verbindung (*.tvc)
[string] $ControlFile,
# Proxy-Konfiguration
[string] $ProxyIP,
[string] $ProxyUser,
[SecureString] $ProxyPassword,
# Dateien an Partner senden
[string[]] $SendTo
)
# Validierungen
if (-not (Test-Path $ExePath)) {
throw "TeamViewer executable not found at: $ExePath"
}
if ($PlayFile -and -not (Test-Path $PlayFile)) {
throw "Play file not found: $PlayFile"
}
if ($ControlFile -and -not (Test-Path $ControlFile)) {
throw "Control file not found: $ControlFile"
}
if ($Password -and $PasswordB64) {
throw "Cannot specify both Password and PasswordB64"
}
if ($ProxyIP -and $ProxyIP -notmatch '^\d+\.\d+\.\d+\.\d+:\d+$') {
throw "ProxyIP must be in format 'IP:Port'"
}
# Argument-Liste erstellen
$argumentList = [System.Collections.Generic.List[string]]::new()
# Basis-Parameter
if ($Minimize) { $argumentList.Add('--Minimize') }
if ($NoInstallation) { $argumentList.Add('--noInstallation') }
# Verbindungs-Parameter
if ($ID) {
$argumentList.Add('--id')
$argumentList.Add($ID)
# Passwort hinzufügen
if ($Password) {
$argumentList.Add('--Password')
$argumentList.Add([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)))
}
elseif ($PasswordB64) {
$argumentList.Add('--PasswordB64')
$argumentList.Add([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PasswordB64)))
}
# Modus (nur wenn nicht Standard)
if ($Mode -and $Mode -ne 'remoteControl') {
$argumentList.Add('--mode')
$argumentList.Add($Mode)
}
# Qualität
if ($Quality) {
$argumentList.Add("--quality$Quality")
}
# Zugriffskontrolle
if ($PSBoundParameters.ContainsKey('AccessControl')) {
$argumentList.Add("--ac$AccessControl")
}
}
# Datei-Parameter (gegenseitig ausschließend)
if ($PlayFile) {
$argumentList.Add('--play')
$argumentList.Add($PlayFile)
}
elseif ($ControlFile) {
$argumentList.Add('--control')
$argumentList.Add($ControlFile)
}
elseif ($SendTo) {
$argumentList.Add('--Sendto')
$argumentList.AddRange($SendTo)
}
# Proxy-Parameter
if ($ProxyIP) {
$argumentList.Add('--ProxyIP')
$argumentList.Add($ProxyIP)
if ($ProxyUser) {
$argumentList.Add('--ProxyUser')
$argumentList.Add($ProxyUser)
}
if ($ProxyPassword) {
$argumentList.Add('--ProxyPassword')
$argumentList.Add([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ProxyPassword)))
}
}
# TeamViewer starten
try {
Write-Verbose "Starting TeamViewer with arguments: $($argumentList -join ' ')"
& $ExePath @argumentList
}
catch {
throw "Failed to start TeamViewer: $_"
}
}
# Zusätzliche Hilfsfunktion für Assignment
function Set-TeamViewerAssignment {
<#
.SYNOPSIS
Weist ein TeamViewer-Gerät einem Account/einer Gruppe zu.
.DESCRIPTION
Diese Funktion verwendet die TeamViewer Assignment-Funktionalität, um ein Gerät
automatisch einem TeamViewer-Account und einer Gruppe zuzuweisen. Dies ist besonders
nützlich für Mass-Deployment-Szenarien.
.PARAMETER ExePath
Pfad zur TeamViewer.exe. Standard: "$Env:ProgramFiles\TeamViewer\TeamViewer.exe"
.PARAMETER ApiToken
API-Token für den Zugriff auf das TeamViewer-Konto (aus Management Console)
.PARAMETER Group
Name der Gruppe, zu der das Gerät hinzugefügt werden soll (wird erstellt falls nicht vorhanden)
.PARAMETER GroupId
ID der Gruppe (Alternative zu Group-Parameter, schneller für große Umgebungen)
.PARAMETER Alias
Alias-Name für das Gerät in der Kontaktliste
.PARAMETER GrantEasyAccess
Gewährt Easy Access nach der Zuweisung
.PARAMETER Reassign
Weist das Gerät zu, auch wenn es bereits einem Account zugewiesen ist
.PARAMETER DataFileTimeout
Wartezeit in Sekunden für die Erstellung der Datendatei (Standard: 10)
.PARAMETER ProxyIP
Proxy-Server im Format 'IP:Port'
.PARAMETER ProxyUser
Benutzername für Proxy-Authentifizierung
.PARAMETER ProxyPassword
Passwort für Proxy-Authentifizierung
.PARAMETER RetryCount
Anzahl der Wiederholungsversuche bei temporären Fehlern (Standard: 3)
.PARAMETER Timeout
Gesamt-Timeout in Sekunden für alle Assignment-Versuche (Standard: 60)
.EXAMPLE
Set-TeamViewerAssignment -ApiToken "12345678" -Group "IT-Support"
Basis-Zuweisung zu einer Gruppe
.EXAMPLE
Set-TeamViewerAssignment -ApiToken "12345678" -Group "Servers" -Alias $env:COMPUTERNAME -GrantEasyAccess
Zuweisung mit Computer-Namen als Alias und Easy Access
.EXAMPLE
Set-TeamViewerAssignment -ApiToken "12345678" -GroupId 12345 -Reassign -ProxyIP "proxy.company.com:8080"
Zuweisung über Proxy mit Gruppen-ID und Reassign-Option
.NOTES
Erfordert Admin-Rechte auf macOS (sudo).
API-Token kann in der TeamViewer Management Console unter "Profil > Apps" erstellt werden.
.LINK
https://www.teamviewer.com/cs/global/support/knowledge-base/teamviewer-remote/deployment/mass-deployment-user-guide/assign-a-device-via-command-line-8-10/
#>
[CmdletBinding()]
param(
[string] $ExePath = "$Env:ProgramFiles\TeamViewer\TeamViewer.exe",
[Parameter(Mandatory)] [string] $ApiToken,
[string] $Group,
[int] $GroupId,
[string] $Alias,
[switch] $GrantEasyAccess,
[switch] $Reassign,
[int] $DataFileTimeout = 10,
[string] $ProxyIP,
[string] $ProxyUser,
[SecureString] $ProxyPassword,
[int] $RetryCount = 3,
[int] $Timeout = 60
)
if (-not (Test-Path $ExePath)) {
throw "TeamViewer executable not found at: $ExePath"
}
if (-not $Group -and -not $GroupId) {
throw "Either Group or GroupId must be specified"
}
$argumentList = [System.Collections.Generic.List[string]]::new()
$argumentList.Add('assign')
$argumentList.Add('--api-token'); $argumentList.Add($ApiToken)
if ($Group) { $argumentList.Add('--group'); $argumentList.Add($Group) }
if ($GroupId) { $argumentList.Add('--groupid'); $argumentList.Add($GroupId) }
if ($Alias) { $argumentList.Add('--alias'); $argumentList.Add($Alias) }
if ($GrantEasyAccess) { $argumentList.Add('--grant-easy-access') }
if ($Reassign) { $argumentList.Add('--reassign') }
if ($DataFileTimeout -ne 10) { $argumentList.Add('--datafolder-timeout'); $argumentList.Add($DataFileTimeout) }
if ($RetryCount -ne 3) { $argumentList.Add('--retry'); $argumentList.Add($RetryCount) }
if ($Timeout -ne 60) { $argumentList.Add('--timeout'); $argumentList.Add($Timeout) }
if ($ProxyIP) {
$argumentList.Add('--proxy'); $argumentList.Add($ProxyIP)
if ($ProxyUser) { $argumentList.Add('--proxy-user'); $argumentList.Add($ProxyUser) }
if ($ProxyPassword) {
$argumentList.Add('--proxy-pw');
$argumentList.Add([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ProxyPassword)))
}
}
try {
Write-Verbose "Assigning TeamViewer with arguments: $($argumentList -join ' ')"
& $ExePath @argumentList
}
catch {
throw "Failed to assign TeamViewer: $_"
}
}
function Start-TeamViewerRemote {
<#
.SYNOPSIS
Öffnet TeamViewer auf erreichbaren AD-Computern, gefiltert nach Name oder Beschreibung.
.DESCRIPTION
Findet Active Directory-Computer anhand eines Suchbegriffs (Computername oder Beschreibung),
prüft deren Erreichbarkeit per Ping und startet TeamViewer für jeden erreichbaren Rechner.
.PARAMETER SearchTerm
Teilstring des Computernamens oder der Beschreibung im AD
.PARAMETER Timeout
Timeout für die Ping-Erreichbarkeitsprüfung in Sekunden (Default: 1)
.EXAMPLE
Start-TeamViewerRemote -SearchTerm "Meier"
.EXAMPLE
Start-TeamViewerRemote -SearchTerm "Laptop" -Timeout 2
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$SearchTerm,
[int]$Timeout = 1
)
$computers = Get-ADComputer -Filter { Enabled -eq $true } -Properties Description |
Where-Object { $_.Description -like "*$SearchTerm*" -or $_.Name -like "*$SearchTerm*" } |
Out-GridView -PassThru
foreach ($comp in $computers) {
Write-Host "Checking if computer is reachable: $($comp.DNSHostName)" -ForegroundColor Yellow
if (Test-Connection -ComputerName $comp.DNSHostName -IPv4 -Ping -Count 1 -Quiet -TimeoutSeconds $Timeout) {
Write-Host "reachable: $($comp.DNSHostName)" -ForegroundColor Green
Start-TeamViewer -ID $comp.DNSHostName
}
else {
Write-Host "not reachable: $($comp.DNSHostName)" -ForegroundColor Red
}
}
}
# Example usage of the Start-TeamViewer function
# Start-TeamViewer -ID "MYHOSTNAME"
$UserOrComputer = Read-Host -Prompt "(Part of) Username (Description) Or Computername"
Start-TeamViewerRemote -SearchTerm $UserOrComputer