|
1 | 1 | <# |
2 | 2 | .SYNOPSIS |
3 | | - Adds users from provided CSV file to SSO exclusion list of their respective domain |
| 3 | + Adds users from a CSV file to the TeamViewer SSO exclusion list of their respective domain. |
4 | 4 |
|
5 | 5 | .DESCRIPTION |
6 | | - The script fetches a list of SSO domains you have configured, loads the CSV file, |
7 | | - will check for email addresses for each of your domains in the CSV and add them to the exclusion list of their repective domain |
8 | | - emails not matching to any of your domains will be skipped |
| 6 | + The script fetches a list of SSO domains you have configured, loads the CSV file, |
| 7 | + will check for email addresses for each of your domains in the CSV and add them to the exclusion list of their repective domain. |
| 8 | + Email addresses not matching to any of your domains will be skipped. |
9 | 9 |
|
10 | 10 | .PARAMETER ApiToken |
11 | 11 | The TeamViewer API token to use. |
12 | 12 | Must be a user access token. |
13 | 13 | The token requires the following access permissions: |
14 | | - - `Manage SSO domains > View details about domains, add and remove email exclusions` |
| 14 | + `Manage SSO domains > View details about domains, add and remove email exclusions` |
15 | 15 |
|
16 | | - .PARAMETER CSVPath |
17 | | - Path of .csv file that contains the emails |
| 16 | + .PARAMETER Path |
| 17 | + Path of a csv file that contains the email addresses. |
18 | 18 |
|
19 | 19 | .PARAMETER HeaderName |
20 | | - Column name where to find emails in imported csv file |
| 20 | + Column name where to find email addresses in the imported csv file. |
21 | 21 |
|
22 | 22 | .EXAMPLE |
23 | 23 | $apiToken = 'SecretToken123' | ConvertTo-SecureString -AsPlainText -Force |
24 | | - .\Add-SsoExclusionsFromCSV -csvPath 'c:\ps playground\test.csv' -HeaderName 'Email' -WhatIf |
| 24 | + .\Add-SsoExclusionsFromCSV -Path 'c:\Example.csv' -HeaderName 'Email' -WhatIf |
25 | 25 |
|
26 | 26 | .NOTES |
27 | | - This script requires the TeamViewerPS module to be installed. |
| 27 | + This script requires the TeamViewerPS module to be installed. |
28 | 28 | This can be done using the following command: |
29 | 29 |
|
30 | 30 | ``` |
31 | 31 | Install-Module TeamViewerPS |
32 | 32 | ``` |
33 | 33 |
|
34 | | - Copyright (c) 2019-2023 TeamViewer GmbH |
35 | | - See file LICENSE.txt |
| 34 | + Copyright (c) 2019-2023 TeamViewer Germany GmbH |
| 35 | + See file LICENSE |
36 | 36 | Version 2.0 |
37 | 37 | #> |
38 | 38 |
|
39 | | -[CmdletBinding(DefaultParameterSetName = "csvPath", SupportsShouldProcess = $true)] |
| 39 | +[CmdletBinding(DefaultParameterSetName = 'Path', SupportsShouldProcess = $true)] |
40 | 40 | param( |
41 | 41 | [Parameter(Mandatory = $true)] |
42 | 42 | [securestring] $ApiToken, |
43 | 43 |
|
44 | 44 | [Parameter(Mandatory = $true)] |
45 | | - [string] $csvPath, |
| 45 | + [string] $Path, |
46 | 46 |
|
47 | 47 | [Parameter(Mandatory = $true)] |
48 | 48 | [string] $HeaderName |
49 | 49 | ) |
50 | 50 |
|
51 | | -if (-Not $MyInvocation.BoundParameters.ContainsKey('ErrorAction')) { $script:ErrorActionPreference = 'Stop' } |
52 | | -if (-Not $MyInvocation.BoundParameters.ContainsKey('InformationAction')) { $script:InformationPreference = 'Continue' } |
| 51 | +if (-Not $MyInvocation.BoundParameters.ContainsKey('ErrorAction')) { |
| 52 | + $script:ErrorActionPreference = 'Stop' |
| 53 | +} |
| 54 | +if (-Not $MyInvocation.BoundParameters.ContainsKey('InformationAction')) { |
| 55 | + $script:InformationPreference = 'Continue' |
| 56 | +} |
53 | 57 |
|
54 | | -function Install-TeamViewerModule { if (!(Get-Module TeamViewerPS)) { Install-Module TeamViewerPS } } |
| 58 | +function Install-TeamViewerModule { |
| 59 | + if (!(Get-Module TeamViewerPS)) { |
| 60 | + Install-Module TeamViewerPS |
| 61 | + } |
| 62 | +} |
55 | 63 |
|
56 | 64 | function Add-SsoExclusionsFromCSV { |
57 | 65 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] |
58 | | - param($csvPath, $HeaderName) |
| 66 | + param($Path, $HeaderName) |
| 67 | + |
| 68 | + # Import email addresses fom csv |
| 69 | + $csvRows = Import-Csv -Path $Path |
59 | 70 |
|
60 | | - #import emails fom csv |
61 | | - $csvRows = Import-Csv -Path $csvPath |
62 | | - |
63 | 71 | if ($csvRows.Count -eq 0) { |
64 | | - Write-Information "No entries found in CSV file" |
| 72 | + Write-Information 'No entries found in CSV file!' |
65 | 73 | exit |
66 | 74 | } |
67 | 75 | else { |
68 | | - Write-Information "Found $($csvRows.Count) rows in CSV file" |
| 76 | + Write-Information "Found $($csvRows.Count) rows in CSV file." |
69 | 77 | } |
70 | | - |
| 78 | + |
71 | 79 | $emails = $csvRows | Select-Object -ExpandProperty $HeaderName |
72 | | - |
| 80 | + |
73 | 81 | if ($emails.Count -eq 0) { |
74 | | - Write-Information "No valid emails found in CSV file" |
| 82 | + Write-Information 'No valid email addresses found in CSV file!' |
75 | 83 | exit |
76 | 84 | } |
77 | 85 | else { |
78 | | - Write-Information "Found $($emails.Count) emails in CSV file" |
| 86 | + Write-Information "Found $($emails.Count) email addresses in CSV file." |
79 | 87 | } |
80 | | - |
| 88 | + |
81 | 89 | $domains = Get-TeamViewerSsoDomain -ApiToken $apiToken |
82 | | - |
| 90 | + |
83 | 91 | if ($domains.Count -eq 0) { |
84 | | - Write-Information "No valid sso domains found" |
| 92 | + Write-Information 'No valid SSO domains found!' |
85 | 93 | exit |
86 | 94 | } |
87 | | - |
| 95 | + |
88 | 96 | foreach ($domain in $domains) { |
89 | | - $domainUsers = $emails | Where-Object -FilterScript { $_.Split("@")[1] -eq $domain.Name } |
90 | | - Write-Information "Adding $($domainUsers.Count) email exclusions for $($domain.Name)" |
| 97 | + $domainUsers = $emails | Where-Object -FilterScript { $_.Split('@')[1] -eq $domain.Name } |
| 98 | + |
| 99 | + Write-Information "Adding $($domainUsers.Count) email exclusions for $($domain.Name)..." |
| 100 | + |
91 | 101 | if ($domainUsers.Count -gt 0 -And -Not $WhatIfPreference) { |
92 | 102 | Add-TeamViewerSsoExclusion -ApiToken $apiToken -DomainId $domain.Id -Email $domainUsers |
93 | | - Write-Information "Completed for domain $($domain.Name)" |
| 103 | + |
| 104 | + Write-Information "Completed for domain $($domain.Name)." |
94 | 105 | } |
95 | 106 | } |
96 | 107 | } |
97 | 108 |
|
98 | 109 | if ($MyInvocation.InvocationName -ne '.') { |
99 | 110 | Install-TeamViewerModule |
100 | | - Add-SsoExclusionsFromCSV -csvPath $csvPath -HeaderName $HeaderName |
| 111 | + |
| 112 | + Add-SsoExclusionsFromCSV -Path $Path -HeaderName $HeaderName |
101 | 113 | } |
0 commit comments