public/New-CloudServerWrapper.ps1

<#PSScriptInfo
 
.VERSION 1.0.0.0
 
.GUID 027e0810-bb33-452c-93ed-83fb7978ec39
 
.AUTHOR Mikail Aras - Meta10
 
.COMPANYNAME Meta10
 
.COPYRIGHT (C) 2024 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.04.15 |mike |Script erstellt.
 
.PRIVATEDATA
 
#>


<# Requires -Module powershell crm classes #>

<#
 
.DESCRIPTION
create new cloud server with credential
 
#>


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

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

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

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

    # import additional modules
    $additionalmodules = [system.collections.generic.list[string]]::new()
    $additionalmodules.add("D:\CEC\script\Get-CloudCustomer.ps1")
    $additionalmodules.add("D:\CEC\script\Get-CloudServer.ps1")
    $additionalmodules.add("D:\CEC\script\New-CloudServer.ps1")
    $additionalmodules.add("D:\CEC\script\Add-CloudServer.ps1")
    $additionalmodules.add("D:\CEC\script\Set-CloudServer.ps1")
    $additionalmodules.add("D:\CEC\script\New-CloudServerCredential.ps1")
    $additionalmodules.add("\\meta10.com\d2system\itservice\script\00_functions\function_new_password.ps1")

    foreach($additionalmodule in $additionalmodules){
        #Unblock-File -Path $additionalmodule
        import-module -name $additionalmodule -force
        write-host "importing module $($additionalmodule)" -ForegroundColor Green

    }

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

    if(Test-CCCRMConnection){
        $cloudcustomer = get-cloudcustomer -name $customername

        if(!([string]::IsNullOrEmpty($cloudcustomer.name))){
            $error.clear()

            $cloudserver = Get-CloudServer -Name $name -Status 'active'

            if(([string]::IsNullOrEmpty($cloudserver.name))){
                # create new cloud server
                $cloudserver = New-CloudServer -Name $name -Role 'app' -OperatingSystem 'windows server 2022 standard' -PrimaryServer $primaryserver -replicaserver $replicaserver

                # create cloud server credential
                $null = New-CloudServerCredential -Name $cloudserver.name -UserName 'Administrator' -Password (new-password) -CredentialType 'local'

                $null = Add-CloudServer -Name $cloudserver.name -CustomerName $customername

            } # end of if
        } # end of if cloudcustomer name

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

        $logal

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

        } # end of foreach
    }
} # end of function