public/Get-CloudCustomer.ps1

param(
  [string] $accesstoken = "none",
  [string] $customer = "none"
)
<#
 
"Start: "+(Get-Date).DateTime
 
. ""$($PSScriptRoot)\Automation\"init-session.ps1"
if ($InitError) {
    Write-Output "Init Error"
    if ($InitError -match "blocked") {
        Write-Output "Session is blocked, try again after previous script finished"
    }
    (Get-Date).DateTime
    exit
}
 
 
 
$CheckAccessOK = CEC-VerifyAccess $accesstoken
 
Write-Log -Level INFO -Message "[$((Get-Item $PSCommandPath).Name)] [$($MyInvocation.MyCommand.Name)] Check Access = $CheckAccessOK"
#>


<#PSScriptInfo
 
.VERSION 1.0.0.0
 
.GUID e12c125d-5cb5-4895-ad04-db6176dee88c
 
.AUTHOR Mikail Aras - Meta10
 
.COMPANYNAME Meta10
 
.COPYRIGHT (C) 2023 by Meta10 - Alle Rechte vorbehalten
 
.TAGS Script PowerSHELL function_connect_exchangeonline_unattended
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
Aenderungsverlauf des Scripts nach dem Schema Major.Minor.Build.Revision,jeweils Major Versionen sind produktiv zu verwenden
Version |Type |Datum |Benutzer |Bemerkungen
1.0.0.0 |BUILD |2023.12.31 |mike |Script erstellt.
 
.PRIVATEDATA
 
#>


<# Requires -Module get-hypervisor #>

<#
 
.DESCRIPTION
set crm server properties with powershell class library
 
#>


function Get-CloudCustomer {
    [CmdletBinding(DefaultParameterSetName='ByName')] # chatgpt provided: You can then set DefaultParameterSetName to one of them (e.g., 'ByName') to make it the default when no parameters are provided.
    param(
        [Parameter(Mandatory=$true, ParameterSetName='ByName')]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [Parameter(Mandatory=$true, ParameterSetName='ByAll')]
        [switch]$All
    )

    $logal = [system.collections.arraylist]::new() # log arraylist

    if(Test-CCCRMConnection){
        if($name){
            $CloudCustomer = [CloudCustomer]::New($name)

            if($cloudcustomer.name){
                $cloudcustomer

            }
            #$CloudCustomer.CloudServers() #| Out-Null
            #$CloudCustomer.CloudAccounts() #| Out-Null

            #$null = $logal.add("configured dns client server address for interface alias $($ethif) with server addresses $($args[2]) and $($args[3])")
        }elseif($all){
            $CloudCustomer = [CloudCustomer]::New() # empty object to later access getall method

            if($cloudcustomer){
                $cloudcustomers = $CloudCustomer.getall()

                if($cloudcustomers){
                    if($CloudCustomer.count -gt 0){
                        $cloudcustomers

                    }else{
                        write-warning -message "found no cloud customers"
                        #$null = $logal.add("found no cloud customers")

                    } # end of if cloudcustomer count
                } # end of if cloudcustomers
            } # end of if cloudcustomer
        } # end of if name

        $logal

        foreach($log in $output){
            #write-customlog -path $pathtolog -message $log -level 'info'

        } # end of foreach
    }
} # end of function

<#
if ($Customer -ne "none") {
    #CEC-BlockState "Block"
    #$cred = CEC-GetCRMCred
    [pscredential]$cred = New-Object System.Management.Automation.PSCredential("meta10\62508.crm-api", (ConvertTo-SecureString "Lr4+4A%CeMBfYd3p" -AsPlainText -Force))
    Connect-CCCRM -Credential $cred
    $CloudCustomer = [CloudCustomer]::New($Customer)
    $CloudCustomer.CloudServers() #| Out-Null
    $CloudCustomer.CloudAccounts() #| Out-Null
    $CloudCustomer
    Export-Clixml -InputObject $CloudCustomer -Path "$Rootpath\CloudCustomer.xml"
    Write-Log -Level INFO -Message "[$((Get-Item $PSCommandPath).Name)] [$($MyInvocation.MyCommand.Name)] XML Export erfolgreich: $Rootpath\CloudCustomer.xml"
    Disconnect-CCCRM
    $cred = $null
    Write-Output "Success, check Automation Log on ScriptSys for Details"
    Write-Log -Level INFO -Message "[$((Get-Item $PSCommandPath).Name)] [$($MyInvocation.MyCommand.Name)] Script End"
    Wait-Logging
    CEC-BlockState "Unblock"
    "End: "+(Get-Date).DateTime
} else {
    Write-Output "Access Denied, invalid Token or Customer"
    "End: "+(Get-Date).DateTime
}
#>