Public/ElementsOpenApi.ps1

function Get-ElementsCustomer {
    [CmdletBinding()]
    Param(
         [Parameter(Mandatory = $false)]
         [String]${Id},
         [Parameter(Mandatory = $false)]
         [String]${OutFile},
         [Parameter(Mandatory = $false)]
         [hashtable]${Filter},
         [Parameter(Mandatory = $false)]
         [bool]${JsonFormat}
    )
    PROCESS {
        if ($Id) {
            if ($Filter) {
                Write-Host 'Unsupported filter: ID' -ForegroundColor Yellow
            }
            $Response = Invoke-ElementsApiV11CustomersIdGet -Id "'$Id'"
        } else {
            if ($Filter) {
                $Response = Invoke-ElementsApiV11CustomersGet -Filter $Filter
            } else {
                $Response = Invoke-ElementsApiV11CustomersGet
            }
        }
        if($OutFile) {
            if ($Id) {
                $result = $Response
            } else {
                $result = $Response.Value
            }
            if ($Id -or $result.Count -gt 0) {
                $folderPath = [System.IO.Path]::GetDirectoryName($OutFile)
                If (-not (Test-Path $folderPath)) {
                    [void](New-Item -Path $folderPath -ItemType Directory)
                }
                $result | Export-Csv -Path $OutFile -NoTypeInformation -Encoding UTF8
                Write-Host 'Successfully. File path:' $OutFile -ForegroundColor Green
            }
            else {
                Write-Host 'No Data' -ForegroundColor Yellow
            }
        } else {
            if($JsonFormat -eq $true) {
                $Response = $Response | ConvertTo-Json
            }
            return $Response
        }
    }
}

function Get-ElementsCustomerJob {
    [CmdletBinding()]
    Param(
         [Parameter(Mandatory = $true)]
         [String]${Id},
         [Parameter(Mandatory = $false)]
         [string]${JobType},
         [Parameter(Mandatory = $false)]
         [string]${JobModule},
         [Parameter(Mandatory = $false)]
         [hashtable]${Filter},
         [Parameter(Mandatory = $false)]
         [String]${OutFile},
         [Parameter(Mandatory = $false)]
         [bool]${JsonFormat}
    )
    PROCESS {
        if($JobType -or $JobModule) {
            if ($JobType) {
                $JobType = "'$JobType'"
            } else {
                $JobType = "null"
            }
            if ($JobModule) {
                $JobModule = "'$JobModule'"
            } else {
                $JobModule = "null"
            }
            if ($Filter) {
                $Response = Invoke-ElementsApiV11CustomersIdJobsJobTypeJobTypeJobModuleJobModuleGet -Id "'$Id'" -JobType "$JobType" -JobModule "$JobModule" -Filter $Filter
            } else {
                $Response = Invoke-ElementsApiV11CustomersIdJobsJobTypeJobTypeJobModuleJobModuleGet -Id "'$Id'" -JobType "$JobType" -JobModule "$JobModule"
            }
        } else {
            if ($Filter) {
                $Response = Invoke-ElementsApiV11CustomersIdJobsGet -Id "'$Id'" -Filter $Filter
            } else {
                $Response = Invoke-ElementsApiV11CustomersIdJobsGet -Id "'$Id'"
            }
        }
        if($OutFile) {
            $result = $Response.Value
            if ($result.Count -gt 0) {
                $folderPath = [System.IO.Path]::GetDirectoryName($OutFile)
                If (-not (Test-Path $folderPath)) {
                    [void](New-Item -Path $folderPath -ItemType Directory)
                }
                $result | Export-Csv -Path $OutFile -NoTypeInformation -Encoding UTF8
                Write-Host 'Successfully. File path:' $OutFile -ForegroundColor Green
            }
            else {
                Write-Host 'No Data' -ForegroundColor Yellow
            }
        } else {
            if($JsonFormat -eq $true) {
                $Response = $Response | ConvertTo-Json
            }
            return $Response
        }
    }
}


function Get-ElementsCustomerProtected {
    [CmdletBinding()]
    Param(
         [Parameter(Mandatory = $true)]
         [String]${Id},
         [Parameter(Mandatory = $false)]
         [String]${OutFile},
         [Parameter(Mandatory = $false)]
         [hashtable]${Filter},
         [Parameter(Mandatory = $false)]
         [bool]${JsonFormat}
    )
    PROCESS {
        if ($Filter) {
            $Response = Invoke-ElementsApiV11CustomersIdProtectedGet -Id "'$Id'" -Filter $Filter
        } else {
            $Response = Invoke-ElementsApiV11CustomersIdProtectedGet -Id "'$Id'"
        }
        if($OutFile) {
            $result = $Response.Value
            if ($result.Count -gt 0) {
                $folderPath = [System.IO.Path]::GetDirectoryName($OutFile)
                If (-not (Test-Path $folderPath)) {
                    [void](New-Item -Path $folderPath -ItemType Directory)
                }
                $result | Export-Csv -Path $OutFile -NoTypeInformation -Encoding UTF8
                Write-Host 'Successfully. File path:' $OutFile -ForegroundColor Green
            }
            else {
                Write-Host 'No Data' -ForegroundColor Yellow
            }
        } else {
            if($JsonFormat -eq $true) {
                $Response = $Response | ConvertTo-Json
            }
            return $Response
        }
    }
}


function Get-ElementsCustomerServices {
    [CmdletBinding()]
    Param(
         [Parameter(Mandatory = $false)]
         [String]${Id},
         [Parameter(Mandatory = $false)]
         [hashtable]${Filter},
         [Parameter(Mandatory = $false)]
         [String]${OutFile},
         [Parameter(Mandatory = $false)]
         [bool]${JsonFormat}
    )
    PROCESS {
        if($Id) {
            if ($Filter) {
                Write-Host 'Unsupported filter: ID' -ForegroundColor Red
            }
            $Response = Invoke-ElementsApiV11ServicesIdGet -Id "'$Id'"
        } else {
            if ($Filter) {
                $Response = Invoke-ElementsApiV11ServicesGet -Filter $Filter
            } else{
                $Response = Invoke-ElementsApiV11ServicesGet
            }
        }
        if($OutFile) {
            if ($Id) {
                $result = $Response
            } else {
                $result = $Response.Value
            }
            if ($Id -or ($result.Count -gt 0)) {
                $folderPath = [System.IO.Path]::GetDirectoryName($OutFile)
                If (-not (Test-Path $folderPath)) {
                    [void](New-Item -Path $folderPath -ItemType Directory)
                }
                $customObjects = @()
                foreach ($customers in $result) {
                    if ($customers.products.Count -gt 0 ) {
                        foreach ($row in $customers.products) {
                            $pros = $customers.PSObject.Properties
                            foreach ($pro in $pros) {
                                if ($pro.TypeNameOfValue -eq "System.String" -or $pro.TypeNameOfValue -eq "System.Object") {
                                    $row | Add-Member -MemberType NoteProperty -Name $pro.Name -Value $pro.Value
                                }
                            }
                            $customObjects += $row
                        }
                    }
                }
                $customObjects | Export-Csv -Path $OutFile -NoTypeInformation -Encoding UTF8
                Write-Host 'Successfully. File path:' $OutFile -ForegroundColor Green
            } else {
                Write-Host 'No Data' -ForegroundColor Yellow
            }
        } else {
            if($JsonFormat -eq $true) {
                $Response = ConvertTo-Json -InputObject $Response -Depth 4
            }
            return $Response
        }
    }
}

function Get-ElementsCustomerScanProfile {
    [CmdletBinding()]
    Param(
         [Parameter(Mandatory = $true)]
         [String]${Id},
         [Parameter(Mandatory = $false)]
         [string]${ProfileId},
         [Parameter(Mandatory = $false)]
         [hashtable]${Filter},
         [Parameter(Mandatory = $false)]
         [String]${OutFile},
         [Parameter(Mandatory = $false)]
         [bool]${JsonFormat}
    )
    PROCESS {
        if($ProfileId) {
            $ProfileId ="'$ProfileId'"
            if ($Filter) {
                $Response = Invoke-ElementsApiV11CustomerIdProfileIdGet -Id "'$Id'" -ProfileId "$ProfileId" -Filter $Filter
            } else {
                $Response = Invoke-ElementsApiV11CustomerIdProfileIdGet -Id "'$Id'" -ProfileId "$ProfileId"
            }
        } else {
            if ($Filter) {
                $Response = Invoke-ElementsApiV11CustomerIdProfileGet -Id "'$Id'" -Filter $Filter
            } else {
                $Response = Invoke-ElementsApiV11CustomerIdProfileGet -Id "'$Id'"
            }
        }
        if($OutFile) {
            if ($ProfileId) {
                $result = $Response
            } else {
                $result = $Response.Value
            }
            if ($ProfileId -or ($result.Count -gt 0)) {
                $folderPath = [System.IO.Path]::GetDirectoryName($OutFile)
                If (-not (Test-Path $folderPath)) {
                    [void](New-Item -Path $folderPath -ItemType Directory)
                }
                $customObjects = @()
                foreach ($customers in $result) {
                    if ($customers.containers.Count -gt 0 ) {
                        foreach ($row in $customers.containers) {
                            $pros = $customers.PSObject.Properties
                            foreach ($pro in $pros) {
                                if ($pro.TypeNameOfValue -eq "System.String" -or $pro.TypeNameOfValue -eq "System.Object") {
                                    $row | Add-Member -MemberType NoteProperty -Name $pro.Name -Value $pro.Value
                                }
                            }
                            $customObjects += $row
                        }
                    }
                }
                $customObjects | Export-Csv -Path $OutFile -NoTypeInformation -Encoding UTF8
                Write-Host 'Successfully. File path:' $OutFile -ForegroundColor Green
            } else {
                Write-Host 'No Data' -ForegroundColor Yellow
            }
        } else {
            if($JsonFormat -eq $true) {
                $Response = ConvertTo-Json -InputObject $Response -Depth 4
            }
            return $Response
        }
    }
}