-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Add TeamViewerSsoInclusion script for importing users to SSO Inclusi…
…on list TEAM-59155
- Loading branch information
1 parent
ee697c3
commit d76ca71
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function Add-TeamViewerSsoInclusion { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[securestring] | ||
$ApiToken, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[ValidateScript( { $_ | Resolve-TeamViewerSsoDomainId } )] | ||
[Alias("Domain")] | ||
[object] | ||
$DomainId, | ||
|
||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[string[]] | ||
) | ||
Begin { | ||
$id = $DomainId | Resolve-TeamViewerSsoDomainId | ||
$resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain/$id/inclusion" | ||
$emailsToAdd = @() | ||
$null = $ApiToken | ||
|
||
function Invoke-RequestInternal { | ||
$body = @{ | ||
emails = @($emailsToAdd) | ||
} | ||
Invoke-TeamViewerRestMethod ` | ||
-ApiToken $ApiToken ` | ||
-Uri $resourceUri ` | ||
-Method Post ` | ||
-ContentType "application/json; charset=utf-8" ` | ||
-Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` | ||
-WriteErrorTo $PSCmdlet ` | ||
-ErrorAction Stop | ` | ||
Out-Null | ||
} | ||
} | ||
Process { | ||
if ($PSCmdlet.ShouldProcess($Email, "Add SSO inclusion")) { | ||
$emailsToAdd += $Email | ||
} | ||
if ($emailsToAdd.Length -eq 100) { | ||
Invoke-RequestInternal | ||
$emailsToAdd = @() | ||
} | ||
} | ||
End { | ||
if ($emailsToAdd.Length -gt 0) { | ||
Invoke-RequestInternal | ||
} | ||
} | ||
} |