diff --git a/PwshAdobeSign.psd1 b/PwshAdobeSign.psd1 index 020ac0b..03879ae 100644 --- a/PwshAdobeSign.psd1 +++ b/PwshAdobeSign.psd1 @@ -70,10 +70,21 @@ # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @( - 'Connect-', 'Connect-AdobeSign' - 'Get-BaseUri', 'Get-AdobeSignBaseUri' - 'Get-Connection', 'Get-AdobeSignConnection' - 'Invoke-Method', 'Invoke-AdobeSignMethod' + 'Add-UserGroup', 'Add-AdobeSignUserGroup' + 'Connect-', 'Connect-AdobeSign' + 'Get-Agreement', 'Get-AdobeSignAgreement' + 'Get-AgreementCombinedDocument', 'Get-AdobeSignAgreementCombinedDocument' + 'Get-BaseUri', 'Get-AdobeSignBaseUri' + 'Get-Connection', 'Get-AdobeSignConnection' + 'Get-Group', 'Get-AdobeSignGroup' + 'Get-User', 'Get-AdobeSignUser' + 'Get-UserGroup', 'Get-AdobeSignUserGroup' + 'Hide-Agreement', 'Hide-AdobeSignAgreement' + 'Invoke-Method', 'Invoke-AdobeSignMethod' + 'Remove-UserGroup', 'Remove-AdobeSignUserGroup' + 'Show-Agreement', 'Show-AdobeSignAgreement' + 'Update-AgreementVisibility', 'Update-AdobeSignAgreementVisibility' + 'Update-UserGroup', 'Update-AdobeSignUserGroup' ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. diff --git a/functions/Add-UserGroup.ps1 b/functions/Add-UserGroup.ps1 new file mode 100644 index 0000000..0cb803e --- /dev/null +++ b/functions/Add-UserGroup.ps1 @@ -0,0 +1,43 @@ + +function Add-UserGroup { + <# + .SYNOPSIS + Adds a user to a group. + .DESCRIPTION + Adds a user to a group. + .EXAMPLE + PS /> Add-AdobeSignUserGroup -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK -GroupId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Adds a user to a group. + .EXAMPLE + PS /> Add-AdobeSignUserGroup -Context $context -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK -GroupId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Adds a user to a group using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] + Param ( + # The ID of the user. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $UserId, + + # The ID of the group. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $GroupId, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + if ($PSCmdlet.ShouldProcess($UserId, 'Add Group Membership')){ + $result = Set-UserGroup @PSBoundParameters -Status 'ACTIVE' -Verbose:$VerbosePreference -Confirm:$false + $result + } +} diff --git a/functions/Get-Agreement.ps1 b/functions/Get-Agreement.ps1 new file mode 100644 index 0000000..2ec1c5e --- /dev/null +++ b/functions/Get-Agreement.ps1 @@ -0,0 +1,76 @@ + +function Get-Agreement { + <# + .SYNOPSIS + Returns a list of agreements or a specified agreement. + .DESCRIPTION + Returns a list of agreements or a specified agreement. + .EXAMPLE + PS /> Get-AdobeSignAgreement + + Gets a list of all agreements + .EXAMPLE + PS /> Get-AdobeSignAgreement -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets an agreement using its id. + .EXAMPLE + PS /> Get-AdobeSignAgreement -GroupId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets all agreements from a group. + .EXAMPLE + PS /> Get-AdobeSignAgreement -ShowHiddenAgreements $true + + Gets all agreements including hidden agreements. + .EXAMPLE + PS /> Get-AdobeSignAgreement -Context $context + + Gets a list of all agreements using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding(DefaultParameterSetName = 'all')] + Param ( + # The ID of the agreement. + [Parameter(Mandatory, ParameterSetName = 'id')] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # The ID of the group. + [Parameter(ParameterSetName = 'all')] + [ValidateNotNullOrEmpty()] + [String] + $GroupId, + + # Show agreements that have been hidden. + [Parameter(ParameterSetName = 'all')] + [Boolean] + $ShowHiddenAgreements = $false, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + switch ($PSCmdlet.ParameterSetName) { + 'id' { + $path = "/agreements/$Id" + } + default { + $path = "/agreements?showHiddenAgreements=$showHiddenAgreements" + if ($PSBoundParameters.ContainsKey('GroupId')) { + $path += "&groupId=$GroupId" + } + } + } + + $result = Invoke-Method -Context $Context -Path $path -Verbose:$VerbosePreference + if ($result) { + if ($result | Get-Member -Name userAgreementList) { + $result | ForEach-Object userAgreementList + } else { + $result + } + } +} diff --git a/functions/Get-AgreementCombinedDocument.ps1 b/functions/Get-AgreementCombinedDocument.ps1 new file mode 100644 index 0000000..80099c0 --- /dev/null +++ b/functions/Get-AgreementCombinedDocument.ps1 @@ -0,0 +1,80 @@ + +function Get-AgreementCombinedDocument { + <# + .SYNOPSIS + Downloads an agreement's combined document + .DESCRIPTION + Downloads an agreement's combined document + .EXAMPLE + PS /> $params = @{ + Id = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + OutFile = 'agreement.pdf' + } + PS /> Update-AdobeSignAgreementCombinedDocument @params + + Downloads an agreement's combined document. + .EXAMPLE + PS /> $params = @{ + Id = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + OutFile = 'agreement.pdf' + AttachAuditReport = $true + } + PS /> Update-AdobeSignAgreementCombinedDocument @params + + Downloads an agreement's combined document with attached audit report. + .EXAMPLE + PS /> $params = @{ + Id = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + OutFile = 'agreement.pdf' + AttachSupportingDocuments = $false + } + PS /> Update-AdobeSignAgreementCombinedDocument @params + + Downloads an agreement's combined document without attached supporting documents. + .EXAMPLE + PS /> $params = @{ + Id = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + OutFile = 'agreement.pdf' + Context = $context + } + PS /> Update-AdobeSignAgreementCombinedDocument @params + + Downloads an agreement's combined document using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding()] + Param ( + # The ID of the agreement. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # File to save response to + [Parameter()] + [ValidateNotNullOrEmpty()] + [String] + $OutFile, + + # If the autdit report should be included + [Parameter()] + [Boolean] + $AttachAuditReport = $false, + + # If all supporting documents should be included + [Parameter()] + [Boolean] + $AttachSupportingDocuments = $true, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + $path = "/agreements/$Id/combinedDocument?attachAuditReport=$AttachAuditReport&attachSupportingDocuments=$AttachSupportingDocuments" + + $result = Invoke-Method -Context $Context -Path $path -OutFile $OutFile -Verbose:$VerbosePreference + $result +} diff --git a/functions/Get-Group.ps1 b/functions/Get-Group.ps1 new file mode 100644 index 0000000..9860985 --- /dev/null +++ b/functions/Get-Group.ps1 @@ -0,0 +1,51 @@ + +function Get-Group { + <# + .SYNOPSIS + Returns a list of groups or a specified group. + .DESCRIPTION + Returns a list of groups or a specified group. + .EXAMPLE + PS /> Get-AdobeSigngroup + + Gets a list of all groups + .EXAMPLE + PS /> Get-AdobeSigngroup -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets a group using its id. + .EXAMPLE + PS /> Get-AdobeSigngroup -Context $context + + Gets a list of all groups using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding()] + Param ( + # The ID of the group. + [Parameter()] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + if ($PSBoundParameters.ContainsKey('Id')) { + $path = "/groups/$Id" + } else { + $path = '/groups' + } + + $result = Invoke-Method -Context $Context -Path $path -Verbose:$VerbosePreference + if ($result) { + if ($result | Get-Member -Name groupInfoList) { + $result | ForEach-Object groupInfoList + } else { + $result + } + } +} diff --git a/functions/Get-User.ps1 b/functions/Get-User.ps1 new file mode 100644 index 0000000..837dfc3 --- /dev/null +++ b/functions/Get-User.ps1 @@ -0,0 +1,51 @@ + +function Get-User { + <# + .SYNOPSIS + Returns a list of users or a specified user. + .DESCRIPTION + Returns a list of users or a specified user. + .EXAMPLE + PS /> Get-AdobeSignUser + + Gets a list of all users + .EXAMPLE + PS /> Get-AdobeSignUser -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets a user using their id. + .EXAMPLE + PS /> Get-AdobeSignUser -Context $context + + Gets a list of all users using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding()] + Param ( + # The ID of the user. + [Parameter()] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + if ($PSBoundParameters.ContainsKey('Id')) { + $path = "/users/$Id" + } else { + $path = '/users' + } + + $result = Invoke-Method -Context $Context -Path $path -Verbose:$VerbosePreference + if ($result) { + if ($result | Get-Member -Name userInfoList) { + $result | ForEach-Object userInfoList + } else { + $result + } + } +} diff --git a/functions/Get-UserGroup.ps1 b/functions/Get-UserGroup.ps1 new file mode 100644 index 0000000..984b388 --- /dev/null +++ b/functions/Get-UserGroup.ps1 @@ -0,0 +1,43 @@ + +function Get-UserGroup { + <# + .SYNOPSIS + Returns a list of groups for a specified user. + .DESCRIPTION + Returns a list of groups for a specified user. + .EXAMPLE + PS /> Get-AdobeSignUserGroup -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets the groups for a user. + .EXAMPLE + PS /> Get-AdobeSignUserGroup -Context $context -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets the groups for a user using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding()] + Param ( + # The ID of the user. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + $path = "/users/$Id/groups" + + $result = Invoke-Method -Context $Context -Path $path -Verbose:$VerbosePreference + if ($result) { + if ($result | Get-Member -Name groupInfoList) { + $result | ForEach-Object groupInfoList + } else { + $result + } + } +} diff --git a/functions/Hide-Agreement.ps1 b/functions/Hide-Agreement.ps1 new file mode 100644 index 0000000..52069ed --- /dev/null +++ b/functions/Hide-Agreement.ps1 @@ -0,0 +1,35 @@ + +function Hide-Agreement { + <# + .SYNOPSIS + Hides a specified agreement. + .DESCRIPTION + Hides a specified agreement. + .EXAMPLE + PS /> Hide-AdobeSignAgreement -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Hides an agreement using its id. + .EXAMPLE + PS /> Hide-AdobeSignAgreement -Context $context -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Hides an agreements using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding()] + Param ( + # The ID of the agreement. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + $result = Update-AgreementVisibility @PSBoundParameters -Visibility 'HIDE' -Verbose:$VerbosePreference -Confirm:$false + $result +} diff --git a/functions/Invoke-Method.ps1 b/functions/Invoke-Method.ps1 index 4ab9cce..4aa3d04 100644 --- a/functions/Invoke-Method.ps1 +++ b/functions/Invoke-Method.ps1 @@ -21,6 +21,10 @@ function Invoke-Method { PS /> Invoke-AdobeSignMethod -Method 'Update' -Path '/users/6' -Body @{ permissions = 64 } Makes a Update request to the /users/{user_id} endpoint to update the permissions level. + .EXAMPLE + PS /> Invoke-AdobeSignMethod -Path '/users/document' -OutFile 'document.pdf' + + Makes a Get request to the /users/document endpoint and saves to the 'document.pdf' file .EXAMPLE PS /> Invoke-AdobeSignMethod -Context $context -Path '/users' @@ -49,6 +53,12 @@ function Invoke-Method { [PSCustomObject] $Body, + # File to save response to + [Parameter()] + [ValidateNotNullOrEmpty()] + [String] + $OutFile, + # Whether to retry when rate limited. [Parameter()] [Boolean] @@ -84,7 +94,7 @@ function Invoke-Method { $params.Token = $Context.IntegrationKey.Password } else { # PS Desktop requires manual header creation. - $params.Headers['Bearer'] = $Context.IntegrationKey.GetNetworkCredential().Password + $params.Headers.Bearer = $Context.IntegrationKey.GetNetworkCredential().Password } if ($PSBoundParameters.ContainsKey('Body')) { @@ -93,6 +103,11 @@ function Invoke-Method { $params.Body | Out-String | Write-Debug } + if ($PSBoundParameters.ContainsKey('OutFile')) { + $params.Headers.Accept = 'application/pdf' + $params.OutFile = $OutFile + } + $uri = $Context.ApiBaseUri + 'api/rest/v6/' + $Path.TrimStart('/') [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 diff --git a/functions/Remove-UserGroup.ps1 b/functions/Remove-UserGroup.ps1 new file mode 100644 index 0000000..e530465 --- /dev/null +++ b/functions/Remove-UserGroup.ps1 @@ -0,0 +1,43 @@ + +function Remove-UserGroup { + <# + .SYNOPSIS + Removes a user from a group. + .DESCRIPTION + Removes a user from a group. + .EXAMPLE + PS /> Remove-AdobeSignUserGroup -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK -GroupId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Removes a user from a group. + .EXAMPLE + PS /> Remove-AdobeSignUserGroup -Context $context -UserId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK -GroupId hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Removes a user from a group using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] + Param ( + # The ID of the user. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $UserId, + + # The ID of the group. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $GroupId, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + if ($PSCmdlet.ShouldProcess($UserId, 'Add Group Membership')){ + $result = Set-UserGroup @PSBoundParameters -Status 'DELETED' -Verbose:$VerbosePreference -Confirm:$false + $result + } +} diff --git a/functions/Show-Agreement.ps1 b/functions/Show-Agreement.ps1 new file mode 100644 index 0000000..f920401 --- /dev/null +++ b/functions/Show-Agreement.ps1 @@ -0,0 +1,35 @@ + +function Show-Agreement { + <# + .SYNOPSIS + Shows a specified agreement. + .DESCRIPTION + Shows a specified agreement. + .EXAMPLE + PS /> Show-AdobeSignAgreement -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Shows an agreement using its id. + .EXAMPLE + PS /> Show-AdobeSignAgreement -Context $context -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Shows an agreements using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding()] + Param ( + # The ID of the agreement. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + $result = Update-AgreementVisibility @PSBoundParameters -Visibility 'SHOW' -Verbose:$VerbosePreference -Confirm:$false + $result +} diff --git a/functions/Update-AgreementVisibility.ps1 b/functions/Update-AgreementVisibility.ps1 new file mode 100644 index 0000000..3f50bc3 --- /dev/null +++ b/functions/Update-AgreementVisibility.ps1 @@ -0,0 +1,57 @@ + +function Update-AgreementVisibility { + <# + .SYNOPSIS + Returns a list of agreements or a specified agreement. + .DESCRIPTION + Returns a list of agreements or a specified agreement. + .EXAMPLE + PS /> Get-AdobeSignAgreement + + Gets a list of all agreements + .EXAMPLE + PS /> Get-AdobeSignAgreement -Id hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK + + Gets an agreement using its id. + .EXAMPLE + PS /> Get-AdobeSignAgreement -Context $context + + Gets a list of all agreements using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] + Param ( + # The ID of the agreement. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $Id, + + [Parameter(Mandatory)] + [ValidateSet('SHOW', 'HIDE')] + [String] + $Visibility, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + $path = "/agreements/$Id/me/visibility" + $Body = @{ + visibility = $Visibility + } + + if ($PSCmdlet.ShouldProcess($Id, "Update visibility: $Visibility")) { + $result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Body $Body -Verbose:$VerbosePreference + if ($result) { + if ($result | Get-Member -Name userAgreementList) { + $result | ForEach-Object userAgreementList + } else { + $result + } + } + } +} diff --git a/functions/Update-UserGroup.ps1 b/functions/Update-UserGroup.ps1 new file mode 100644 index 0000000..037ed94 --- /dev/null +++ b/functions/Update-UserGroup.ps1 @@ -0,0 +1,116 @@ + +function Update-UserGroup { + <# + .SYNOPSIS + Updates the group assignments for a user + .DESCRIPTION + Updates the group assignments for a user + .EXAMPLE + PS /> $params = @{ + UserId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + GroupId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + Status = 'Active' + } + PS /> Update-AdobeSignUserGroup @params + + Adds a user to a group. + .EXAMPLE + PS /> $params = @{ + UserId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + GroupId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + Status = 'Remove' + } + PS /> Update-AdobeSignUserGroup @params + + Removes a user from a group. + .EXAMPLE + PS /> $params = @{ + UserId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + GroupId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + Status = 'Active' + GroupAdmin = $true + } + PS /> Update-AdobeSignUserGroup @params + + Makes the user a group admin. + .EXAMPLE + PS /> $params = @{ + UserId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + GroupId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + Status = 'Active' + PrimaryGroup = $true + } + PS /> Update-AdobeSignUserGroup @params + + Makes the group primary for a user. + .EXAMPLE + PS /> $params = @{ + UserId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + GroupId = 'hXy4R2NaYnvTaftrEhaD4ZAJrxh3YM8kuf8CupEouFoK' + Status = 'Active' + Context = $context + } + PS /> Update-AdobeSignUserGroup @params + + Adds a user to a group using a connection context. + #> + [OutputType([PSCustomObject])] + [CMDletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] + Param ( + # The ID of the user. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $UserId, + + # The ID of the group. + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [String] + $GroupId, + + [Parameter()] + [ValidateSet('ACTIVE', 'DELETED')] + [String] + $Status = 'ACTIVE', + + # Make the user a group admin + [Parameter()] + [Boolean] + $GroupAdmin, + + # Set as the primary group for the user + [Parameter()] + [Boolean] + $PrimaryGroup, + + # Adobe Sign Connection Context from `Get-AdobeSignConnection` + [Parameter()] + [PSTypeName('AdobeSignContext')] + [PSCustomObject] + $Context = $null + ) + + $path = "/users/$UserId/groups" + $body = @{ + groupInfoList = @( + @{ + id = $GroupId + status = $Status + } + ) + } + + if ($PSBoundParameters.ContainsKey('GroupAdmin')) { + $body.groupInfoList[0].isGroupAdmin = $GroupAdmin + } + + if ($PSBoundParameters.ContainsKey('PrimaryGroup')) { + $body.groupInfoList[0].isPrimaryGroup = $PrimaryGroup + } + + if ($PSCmdlet.ShouldProcess($UserId, 'Set Group Membership')){ + $result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Body $body -Verbose:$VerbosePreference + $result + } +}