Skip to content

Commit

Permalink
-Add TeamViewerSsoInclusion script for importing users to SSO Inclusi…
Browse files Browse the repository at this point in the history
…on list

TEAM-59155
  • Loading branch information
hasmikbars committed Oct 30, 2024
1 parent ee697c3 commit d76ca71
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Cmdlets/Public/Add-TeamViewerSsoInclusion.ps1
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[]]
$Email
)
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
}
}
}

0 comments on commit d76ca71

Please sign in to comment.