Model/MachineAccountCreateRequestInputV2.ps1

#
# SailPoint Identity Security API - Machine Account Creation Request
# Use these APIs to interact with the SailPoint Identity Security platform to achieve repeatable, automated processes with greater scalability. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.
# Version: v1
# Generated by OpenAPI Generator: https://openapi-generator.tech
#

<#
.SYNOPSIS

No summary available.

.DESCRIPTION

Contains the information for processing a user-initiated machine account creation request. Adds a target source and per-entitlement request details to the v1 request.

.PARAMETER SubtypeId
Subtype ID for which machine account create is enabled and user have the entitlement to create the machine account.
.PARAMETER SourceId
ID of the source to create the machine account on. The subtype must be available on this source. Required when subtypes can be configured per source for the tenant; otherwise it is ignored and the subtype's own source is used.
.PARAMETER FormId
Form ID selected by user for the machine account create request.
.PARAMETER OwnerIdentityId
Owner Identity ID. This identity will be assigned as an owner of the created machine account.
.PARAMETER MachineIdentityId
Machine identity to correlate with the created machine account. If not provided, a new machine identity will be created.
.PARAMETER Environment
Environment type to use for the machine account.
.PARAMETER Description
Description for the machine account.
.PARAMETER UserInput
Fields of the form linked to the subtype in approval settings.
.PARAMETER Entitlements
Entitlements to request for the created machine account, each with an optional comment, start date, and remove date. Duplicate IDs are ignored and up to 20 unique entitlements are allowed. Use either `entitlements` or `entitlementIds`, depending on which one your tenant supports; sending a non-empty list that your tenant does not support returns `400`.
.PARAMETER EntitlementIds
List of entitlement IDs to provision for created machine account. Up to 20 unique entitlements are allowed. Use either `entitlements` or `entitlementIds`, depending on which one your tenant supports; sending a non-empty list that your tenant does not support returns `400`.
.OUTPUTS

MachineAccountCreateRequestInputV2<PSCustomObject>
#>


function Initialize-MachineAccountCreateRequestInputV2 {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${SubtypeId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${SourceId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${FormId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${OwnerIdentityId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${MachineIdentityId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${Environment},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${Description},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${UserInput},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${Entitlements},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String[]]
        ${EntitlementIds}
    )

    Process {
        'Creating PSCustomObject: PSSailpoint.MachineAccountCreationRequest => MachineAccountCreateRequestInputV2' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        if (!$SubtypeId) {
            throw "invalid value for 'SubtypeId', 'SubtypeId' cannot be null."
        }

        if (!$OwnerIdentityId) {
            throw "invalid value for 'OwnerIdentityId', 'OwnerIdentityId' cannot be null."
        }


        $PSO = [PSCustomObject]@{
            "subtypeId" = ${SubtypeId}
            "sourceId" = ${SourceId}
            "formId" = ${FormId}
            "ownerIdentityId" = ${OwnerIdentityId}
            "machineIdentityId" = ${MachineIdentityId}
            "environment" = ${Environment}
            "description" = ${Description}
            "userInput" = ${UserInput}
            "entitlements" = ${Entitlements}
            "entitlementIds" = ${EntitlementIds}
        }

        return $PSO
    }
}

<#
.SYNOPSIS

Convert from JSON to MachineAccountCreateRequestInputV2<PSCustomObject>

.DESCRIPTION

Convert from JSON to MachineAccountCreateRequestInputV2<PSCustomObject>

.PARAMETER Json

Json object

.OUTPUTS

MachineAccountCreateRequestInputV2<PSCustomObject>
#>

function ConvertFrom-JsonToMachineAccountCreateRequestInputV2 {
    Param(
        [AllowEmptyString()]
        [string]$Json
    )

    Process {
        'Converting JSON to PSCustomObject: PSSailpoint.MachineAccountCreationRequest => MachineAccountCreateRequestInputV2' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in MachineAccountCreateRequestInputV2
        $AllProperties = ("subtypeId", "sourceId", "formId", "ownerIdentityId", "machineIdentityId", "environment", "description", "userInput", "entitlements", "entitlementIds")
        foreach ($name in $JsonParameters.PsObject.Properties.Name) {
            if (!($AllProperties.Contains($name))) {
                throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
            }
        }

        If ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") { # empty json
            throw "Error! Empty JSON cannot be serialized due to the required property 'subtypeId' missing."
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "subtypeId"))) {
            throw "Error! JSON cannot be serialized due to the required property 'subtypeId' missing."
        } else {
            $SubtypeId = $JsonParameters.PSobject.Properties["subtypeId"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "ownerIdentityId"))) {
            throw "Error! JSON cannot be serialized due to the required property 'ownerIdentityId' missing."
        } else {
            $OwnerIdentityId = $JsonParameters.PSobject.Properties["ownerIdentityId"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "sourceId"))) { #optional property not found
            $SourceId = $null
        } else {
            $SourceId = $JsonParameters.PSobject.Properties["sourceId"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "formId"))) { #optional property not found
            $FormId = $null
        } else {
            $FormId = $JsonParameters.PSobject.Properties["formId"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "machineIdentityId"))) { #optional property not found
            $MachineIdentityId = $null
        } else {
            $MachineIdentityId = $JsonParameters.PSobject.Properties["machineIdentityId"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "environment"))) { #optional property not found
            $Environment = $null
        } else {
            $Environment = $JsonParameters.PSobject.Properties["environment"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "description"))) { #optional property not found
            $Description = $null
        } else {
            $Description = $JsonParameters.PSobject.Properties["description"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "userInput"))) { #optional property not found
            $UserInput = $null
        } else {
            $UserInput = $JsonParameters.PSobject.Properties["userInput"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "entitlements"))) { #optional property not found
            $Entitlements = $null
        } else {
            $Entitlements = $JsonParameters.PSobject.Properties["entitlements"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "entitlementIds"))) { #optional property not found
            $EntitlementIds = $null
        } else {
            $EntitlementIds = $JsonParameters.PSobject.Properties["entitlementIds"].value
        }

        $PSO = [PSCustomObject]@{
            "subtypeId" = ${SubtypeId}
            "sourceId" = ${SourceId}
            "formId" = ${FormId}
            "ownerIdentityId" = ${OwnerIdentityId}
            "machineIdentityId" = ${MachineIdentityId}
            "environment" = ${Environment}
            "description" = ${Description}
            "userInput" = ${UserInput}
            "entitlements" = ${Entitlements}
            "entitlementIds" = ${EntitlementIds}
        }

        return $PSO
    }

}