Categories.psm1




<#
.SYNOPSIS
    The get HidDelegatedFormCategory operation will retrieve a list of delegatedform categories from your company.
.DESCRIPTION
    The get HidDelegatedFormCategory operation will retrieve a list of users from your company. This can be either all users, or single categories by guid or name
.PARAMETER Name
    Specifies the name of a DelegatedFormCategory to retrieve, can be specified as an array of strings to retrieve multiple categories
.PARAMETER DelegatedFormCategoryGuid
    Specifies the Guid of a DelegatedFormCategory to retrieve, can be specified as an array of Guids to retrieve multiple categories
.PARAMETER CompanyName
    The companyname that's used in the helloId URL to know which HelloID tenant to talk to. Required if not connected with Connect-HelloId.
.PARAMETER ApiKey
    The Apikey to use for the api call. Required if not connected with Connect-HelloId.
.PARAMETER ApiSecret
    The Apisecret belonging to the apikey, has to be a securestring. Required if not connected with Connect-HelloId.
.EXAMPLE
    Get-HidDelegatedFormCategory
    Returns all the delegatedform categories in the tenant
.EXAMPLE
    Get-HidDelegatedFormCategory -guid [guid]
    Returns the categorie with the mentioned guid
.EXAMPLE
    Get-HidDelegatedFormCategory -name testcat1
    Returns only the categorie with name testcat1
.INPUTS
    
.OUTPUTS
    
#>

function Get-HidDelegatedFormCategory {
    [CmdletBinding(DefaultParameterSetName = 'guid',PositionalBinding = $false)]
    [Alias()]
    [OutputType([String])]
    Param ( 
        # the name of an existing variable
        [Parameter(Mandatory = $false,
        ValueFromPipeline = $true,
        ValueFromPipelineByPropertyName = $true,
        ParameterSetName = "guid")]
        [ValidateNotNullOrEmpty()]
        [Alias("Guid")]
        [guid[]]$DelegatedFormCategoryGuid, 
    
        # the name of an existing variable
        [Parameter(Mandatory = $false,
        ValueFromPipeline = $true,
        ValueFromPipelineByPropertyName = $true,
        ParameterSetName = "Name")]
        [ValidateNotNullOrEmpty()]
        [Alias("DelegatedFormCategoryName")]
        [string[]]$Name,
        
        # Company name used in the URL
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [string]$CompanyName,
        
        # Api key
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [string]$ApiKey,

        # Api secret
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [securestring]$ApiSecret
    )
    
    begin {

        if ($PSBoundParameters.ContainsKey("CompanyName") -AND $PSBoundParameters.ContainsKey("ApiKey") -AND $PSBoundParameters.ContainsKey("ApiSecret") ){
            Write-Verbose -Message "Using connectioninfo and credentials from parameter"
            #Create credential object for authentication
            $Cred = New-Object System.Management.Automation.PSCredential ($ApiKey, $ApiSecret)
        }
        elseif ($Global:HelloIdConnection.ApiCredentials) {
            Write-Verbose -Message "Using Global connectioninfo and credentials from Connect-HelloId "
            $Cred = $Global:HelloIdConnection.ApiCredentials
            $CompanyName = $Global:HelloIdConnection.CompanyName
        }
        else {            
            throw "Error finding connectioninfo. Connect using Connect-HelloId, or specify CompanyName, ApiKey and ApiSecret"
        }

        #Headers
        $headers = @{
            "Content-Type" = "application/json"
        }  

    } #End begin
    
    process {        

        if ($PSBoundParameters.ContainsKey("DelegatedFormCategoryGuid")){            
            foreach ($guid in $DelegatedFormCategoryGuid){
                $URI = "https://$CompanyName.helloid.com/api/v1/delegatedformcategories/$guid"
                $output = Invoke-RestMethod -Uri $URI -Method "GET" -Headers $headers -Credential $Cred -UseBasicParsing               
                $output
            }

        }
        elseif ($PSBoundParameters.ContainsKey("Name")) {
            foreach ($delformname in $Name){
                $URI = "https://$CompanyName.helloid.com/api/v1/delegatedformcategories/$delformname"
                $output = Invoke-RestMethod -Uri $URI -Method "GET" -Headers $headers -Credential $Cred -UseBasicParsing
                $output
            }
        }        
        else {               
            $URI = "https://$CompanyName.helloid.com/api/v1/delegatedformcategories"

            $output = Invoke-RestMethod -Uri $URI -Method "GET" -Headers $headers -Credential $Cred -UseBasicParsing
            $output

           
        } #end else
    } #End process
    
    end {
        
    } #End end
} #End function






<#
.SYNOPSIS
    The Set HidDelegatedFormCategory operation will create or update a delegated form category.
.DESCRIPTION
    The Set HidDelegatedFormCategory operation will create or update a delegated form category
.PARAMETER Name
    Hashtable of the categorie name in differnt languages. 'en' is required, optional languages are: 'nl','fr','de','it','es'
.PARAMETER DelegatedFormCategoryGuid
    Specifies the Guid of a DelegatedFormCategory to update, if not present it will create a new category
.PARAMETER CompanyName
    The companyname that's used in the helloId URL to know which HelloID tenant to talk to. Required if not connected with Connect-HelloId.
.PARAMETER ApiKey
    The Apikey to use for the api call. Required if not connected with Connect-HelloId.
.PARAMETER ApiSecret
    The Apisecret belonging to the apikey, has to be a securestring. Required if not connected with Connect-HelloId.
.EXAMPLE
    Get-HidDelegatedFormCategory
    Returns all the delegatedform categories in the tenant
.EXAMPLE
    Get-HidDelegatedFormCategory -guid [guid]
    Returns the categorie with the mentioned guid
.EXAMPLE
    Get-HidDelegatedFormCategory -name testcat1
    Returns only the categorie with name testcat1
.INPUTS
    
.OUTPUTS
    
#>

function Set-HidDelegatedFormCategory {
    [CmdletBinding(DefaultParameterSetName = 'guid',PositionalBinding = $false)]
    [Alias()]
    [OutputType([String])]
    Param ( 
        [Parameter(Mandatory = $false,
        ValueFromPipeline = $true,
        ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [Alias("Guid")]
        [guid]$DelegatedFormCategoryGuid,    
        
        [Parameter(Mandatory = $true,
        ValueFromPipeline = $false,
        ValueFromPipelineByPropertyName = $false)]
        [ValidateNotNullOrEmpty()]
        [Alias("DelegatedFormCategoryName")]
        [hashtable]$Name,
        
        # Company name used in the URL
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [string]$CompanyName,
        
        # Api key
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [string]$ApiKey,

        # Api secret
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [securestring]$ApiSecret
    )
    
    begin {

        if ($PSBoundParameters.ContainsKey("CompanyName") -AND $PSBoundParameters.ContainsKey("ApiKey") -AND $PSBoundParameters.ContainsKey("ApiSecret") ){
            Write-Verbose -Message "Using connectioninfo and credentials from parameter"
            #Create credential object for authentication
            $Cred = New-Object System.Management.Automation.PSCredential ($ApiKey, $ApiSecret)
        }
        elseif ($Global:HelloIdConnection.ApiCredentials) {
            Write-Verbose -Message "Using Global connectioninfo and credentials from Connect-HelloId "
            $Cred = $Global:HelloIdConnection.ApiCredentials
            $CompanyName = $Global:HelloIdConnection.CompanyName
        }
        else {            
            throw "Error finding connectioninfo. Connect using Connect-HelloId, or specify CompanyName, ApiKey and ApiSecret"
        }

        #Headers
        $headers = @{
            "Content-Type" = "application/json"
        }
        
        #Variables
        $catNames = $Name | ConvertTo-Json

    } #End begin
    
    process {        

        $Body = @"
{
    "delegatedFormCategoryGuid": "$DelegatedFormCategoryGuid",
    "name": $catNames
}
"@

        
        $URI = "https://$CompanyName.helloid.com/api/v1/delegatedformcategories"
        Write-Debug "Body is:`n $($Body)"
        $output = Invoke-RestMethod -Uri $URI -Method "POST" -Headers $headers -Credential $Cred -UseBasicParsing -Body $Body
        $output
           
    } #End process
    
    end {
        
    } #End end
} #End function





<#
.SYNOPSIS
    Removes a DelegatedForm Category
.DESCRIPTION
    Removes a DelegatedForm Category based on the guid
.PARAMETER DelegatedFormCategoryGuid
    Specifies the Guid of an existing category to remove, can be specified as an array of strings to remove multiple categories
.PARAMETER CompanyName
    The companyname that's used in the helloId URL to know which HelloID tenant to talk to. Required if not connected with Connect-HelloId.
.PARAMETER ApiKey
    The Apikey to use for the api call. Required if not connected with Connect-HelloId.
.PARAMETER ApiSecret
    The Apisecret belonging to the apikey, has to be a securestring. Required if not connected with Connect-HelloId.
.EXAMPLE
    Remove-HidDelegatedFormCategory -DelegatedFormCategoryGuid "c31fd53a-b346-4bb4-9a67-f9406d3968db"

    Removes the category with the specified GUID
.INPUTS
    Inputs to this cmdlet (if any)
.OUTPUTS
    Output from this cmdlet (if any)
#>

function Remove-HidDelegatedFormCategory {
    [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1',
        PositionalBinding = $false)]
    [Alias()]
    [OutputType([String])]
    Param (
        # the GUID of an existing category
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true)]
        [alias("Guid")]
        [ValidateNotNullOrEmpty()]
        [guid[]]$DelegatedFormCategoryGuid,        
        
        # Company name used in the URL
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [string]$CompanyName,
        
        # Api key
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [string]$ApiKey,

        # Api secret
        [Parameter(Mandatory= $false)]
        [ValidateNotNullOrEmpty()]
        [securestring]$ApiSecret
    )
    
    begin {
        if ($PSBoundParameters.ContainsKey("CompanyName") -AND $PSBoundParameters.ContainsKey("ApiKey") -AND $PSBoundParameters.ContainsKey("ApiSecret") ){
            Write-Verbose -Message "Using connectioninfo and credentials from parameter"
            #Create credential object for authentication
            $Cred = New-Object System.Management.Automation.PSCredential ($ApiKey, $ApiSecret)
        }
        elseif ($Global:HelloIdConnection.ApiCredentials) {
            Write-Verbose -Message "Using Global connectioninfo and credentials from Connect-HelloId "
            $Cred = $Global:HelloIdConnection.ApiCredentials
            $CompanyName = $Global:HelloIdConnection.CompanyName
        }
        else {            
            throw "Error finding connectioninfo. Connect using Connect-HelloId, or specify CompanyName, ApiKey and ApiSecret"
        }

        #Headers
        $headers = @{
            "Content-Type" = "application/json"
        }
        
        
    } #End begin
    
    process {        

        foreach ($guid in $DelegatedFormCategoryGuid){
        #Uri
        $URI = "https://$CompanyName.helloid.com/api/v1/delegatedformcategories/$guid"        
        Invoke-RestMethod -Uri $URI -Method "DELETE" -Headers $headers -Credential $Cred -UseBasicParsing        
        } #end foreach

    } #End process
    
    end {
    } #End end
} #End function