Skip to content

Commit ca12419

Browse files
Merge pull request #27 from teamviewer/Adaptions_Add-SSOExclusions
Adaptions add sso exclusions
2 parents b4ee7f4 + e3b4594 commit ca12419

File tree

4 files changed

+68
-59
lines changed

4 files changed

+68
-59
lines changed

Add-SsoExclusionsFromCSV/Add-SsoExclusionsFromCSV.Tests.ps1

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
# Copyright (c) 2019-2021 TeamViewer GmbH
2-
# See file LICENSE.txt
1+
# Copyright (c) 2019-2023 TeamViewer Germany GmbH
2+
# See file LICENSE
33

44
BeforeAll {
55
$testApiToken = [securestring]@{}
6-
. "$PSScriptRoot\Add-SsoExclusionsFromCSV.ps1" `
7-
-ApiToken $testApiToken `
8-
-csvPAth "testPath" `
9-
-HeaderName "Email" `
10-
-InformationAction 'SilentlyContinue'
6+
. "$PSScriptRoot\Add-SsoExclusionsFromCSV.ps1" -ApiToken $testApiToken -Path 'testPath' -HeaderName 'Email' -InformationAction 'SilentlyContinue'
117

128
Mock Invoke-TeamViewerPing { $true }
139
Mock Get-TeamViewerSsoDomain { @(
14-
[PSCustomObject]@{Id = '9602c5f4-2779-4f9a-80e8-4829531789fe'; Name = "example1.org" },
15-
[PSCustomObject]@{Id = '33ad81bb-e88b-46d0-92e1-b4f1663abf31'; Name = "example2.org" }
10+
[PSCustomObject]@{Id = '9602c5f4-2779-4f9a-80e8-4829531789fe'; Name = 'example1.org' },
11+
[PSCustomObject]@{Id = '33ad81bb-e88b-46d0-92e1-b4f1663abf31'; Name = 'example2.org' }
1612
)
1713
}
1814
Mock Add-TeamViewerSsoExclusion {}
@@ -22,9 +18,9 @@ BeforeAll {
2218
"user1@example1.org","User1"
2319
"user2@example1.org","User2"
2420
"user3@example2.org","User3"
25-
"user4@example2.org","User4"
21+
"user4@example2.org","User4"
2622
"user5@example2.org","User5"
27-
"user5@example3.org","User6"
23+
"user5@example3.org","User6"
2824
'@
2925
}
3026

@@ -54,16 +50,12 @@ BeforeAll {
5450
Describe 'Add-SsoExclusionsFromCSV' {
5551

5652
It 'Should blah' {
57-
Add-SsoExclusionsFromCSV -csvPath "example.csv" -HeaderName "Email"
53+
Add-SsoExclusionsFromCSV -Path 'example.csv' -HeaderName 'Email'
5854

5955
Assert-MockCalled Get-TeamViewerSsoDomain -Times 1 -Scope It
6056
Assert-MockCalled Add-TeamViewerSsoExclusion -Times 1 -Scope It -ParameterFilter {
61-
$ApiToken -eq $testApiToken -And `
62-
$DomainId -eq [guid]'9602c5f4-2779-4f9a-80e8-4829531789fe' -And `
63-
$Email.Count -eq 2 }
57+
$ApiToken -eq $testApiToken -And $DomainId -eq [guid]'9602c5f4-2779-4f9a-80e8-4829531789fe' -And $Email.Count -eq 2 }
6458
Assert-MockCalled Add-TeamViewerSsoExclusion -Times 1 -Scope It -ParameterFilter {
65-
$ApiToken -eq $testApiToken -And `
66-
$DomainId -eq [guid]'33ad81bb-e88b-46d0-92e1-b4f1663abf31' -And `
67-
$Email.Count -eq 3 }
59+
$ApiToken -eq $testApiToken -And $DomainId -eq [guid]'33ad81bb-e88b-46d0-92e1-b4f1663abf31' -And $Email.Count -eq 3 }
6860
}
6961
}
Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,113 @@
11
<#
22
.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.
44
55
.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.
99
1010
.PARAMETER ApiToken
1111
The TeamViewer API token to use.
1212
Must be a user access token.
1313
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`
1515
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.
1818
1919
.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.
2121
2222
.EXAMPLE
2323
$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
2525
2626
.NOTES
27-
This script requires the TeamViewerPS module to be installed.
27+
This script requires the TeamViewerPS module to be installed.
2828
This can be done using the following command:
2929
3030
```
3131
Install-Module TeamViewerPS
3232
```
3333
34-
Copyright (c) 2019-2023 TeamViewer GmbH
35-
See file LICENSE.txt
34+
Copyright (c) 2019-2023 TeamViewer Germany GmbH
35+
See file LICENSE
3636
Version 2.0
3737
#>
3838

39-
[CmdletBinding(DefaultParameterSetName = "csvPath", SupportsShouldProcess = $true)]
39+
[CmdletBinding(DefaultParameterSetName = 'Path', SupportsShouldProcess = $true)]
4040
param(
4141
[Parameter(Mandatory = $true)]
4242
[securestring] $ApiToken,
4343

4444
[Parameter(Mandatory = $true)]
45-
[string] $csvPath,
45+
[string] $Path,
4646

4747
[Parameter(Mandatory = $true)]
4848
[string] $HeaderName
4949
)
5050

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+
}
5357

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+
}
5563

5664
function Add-SsoExclusionsFromCSV {
5765
[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
5970

60-
#import emails fom csv
61-
$csvRows = Import-Csv -Path $csvPath
62-
6371
if ($csvRows.Count -eq 0) {
64-
Write-Information "No entries found in CSV file"
72+
Write-Information 'No entries found in CSV file!'
6573
exit
6674
}
6775
else {
68-
Write-Information "Found $($csvRows.Count) rows in CSV file"
76+
Write-Information "Found $($csvRows.Count) rows in CSV file."
6977
}
70-
78+
7179
$emails = $csvRows | Select-Object -ExpandProperty $HeaderName
72-
80+
7381
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!'
7583
exit
7684
}
7785
else {
78-
Write-Information "Found $($emails.Count) emails in CSV file"
86+
Write-Information "Found $($emails.Count) email addresses in CSV file."
7987
}
80-
88+
8189
$domains = Get-TeamViewerSsoDomain -ApiToken $apiToken
82-
90+
8391
if ($domains.Count -eq 0) {
84-
Write-Information "No valid sso domains found"
92+
Write-Information 'No valid SSO domains found!'
8593
exit
8694
}
87-
95+
8896
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+
91101
if ($domainUsers.Count -gt 0 -And -Not $WhatIfPreference) {
92102
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)."
94105
}
95106
}
96107
}
97108

98109
if ($MyInvocation.InvocationName -ne '.') {
99110
Install-TeamViewerModule
100-
Add-SsoExclusionsFromCSV -csvPath $csvPath -HeaderName $HeaderName
111+
112+
Add-SsoExclusionsFromCSV -Path $Path -HeaderName $HeaderName
101113
}

Add-SsoExclusionsFromCSV/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add-SsoExclusionsFromCSV
22

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.
44

55
## Prerequisites
66

@@ -15,20 +15,20 @@ Install-Module TeamViewerPS
1515
### Import users from a CSV file
1616

1717
```powershell
18-
.\Add-SsoExclusionsFromCSV -csvPath 'c:\ps playground\test.csv' -HeaderName 'Email'
18+
.\Add-SsoExclusionsFromCSV -Path 'c:\Example.csv' -HeaderName 'Email'
1919
```
2020

21-
### Import users from a CSV file that uses semi-colon as delimiter. Use the given API token
21+
### Import users from a CSV file and use the given API token
2222

2323
```powershell
2424
$apiToken = 'SecretToken123' | ConvertTo-SecureString -AsPlainText -Force
25-
.\Add-SsoExclusionsFromCSV -csvPath 'c:\ps playground\test.csv' -HeaderName 'Email'
25+
.\Add-SsoExclusionsFromCSV -Path 'c:\Example.csv' -HeaderName 'Email'
2626
```
2727

28-
### Run the import script in "Test Mode" to see the changes that would be made.
28+
### Run the import script in "Test Mode" to see the changes that would be made
2929

3030
```powershell
31-
.\Add-SsoExclusionsFromCSV -csvPath 'c:\ps playground\test.csv' -HeaderName 'Email' -WhatIf
31+
.\Add-SsoExclusionsFromCSV -Path 'c:\Example.csv' -HeaderName 'Email' -WhatIf
3232
```
3333

3434
## More help

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ A continously growing set of Powershell example scripts that showcase the
77

88
## Contents
99

10+
### [Add-SsoExclusionsFromCSV](./Add-SsoExclusionsFromCSV)
11+
12+
* 📜 Adds users from a CSV file to the TeamViewer SSO exclusion list of their respective domain.
13+
* ⚙️ [TeamViewerPS](https://github.com/teamviewer/TeamViewerPS) module needed
14+
1015
### [Set-TeamViewerDevicesPolicy](./Set-TeamViewerDevicesPolicy)
1116

1217
* 📜 Sets the policy for all / specific devices to specific policy or inherits policy from group.

0 commit comments

Comments
 (0)