public/New-CloudServer.ps1

<#PSScriptInfo
 
.VERSION 1.0.0.0
 
.GUID ff4c5348-0700-4b83-9d49-2ac057716b0a
 
.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 |2024.01.15 |mike |Script erstellt.
 
.PRIVATEDATA
 
#>


<# Requires -Module get-hypervisor #>

<#
 
.DESCRIPTION
new crm server
 
#>


function New-CloudServer {
    param(
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [ValidateSet('Active Directory', 'Session Host', 'Gateway', 'File', 'App', 'Management', 'Security Gateway', 'CRM', 'Sharepoint', 'ADFS')]
        [string]$Role,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [ValidateSet('Windows Server 2022 Standard', 'Windows Server 2022 Core Standard', 'Vyos')]
        [string]$OperatingSystem,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$PrimaryServer,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$ReplicaServer

    )

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

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

            if($cloudserver){
                $error.clear()

                try{
                    $cloudserver.newserver($name, $primaryserver, $replicaserver, $role, $operatingsystem) # new cloud server
                    write-host "created cloud server $($name) with role $($role), primary server $($primaryserver) and operating system $($operatingsystem)" -foregroundcolor 'yellow'

                }catch{
                    write-error -message "couldnt create cloud server $($name) due to following error $($error[-1].exception)"

                } # end of try catch block
            } # end of if primary server

            #$null = $logal.add("configured dns client server address for interface alias $($ethif) with server addresses $($args[2]) and $($args[3])")
        } # end of if computername

        $logal

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

        } # end of foreach
    }
} # end of function