Public/Export-P1Environment.ps1

function Export-P1Environment {
    <#
    .Synopsis
    Export PlannerOne environment to file.
 
    .Description
    Export an existing and initialized environment save it to file system.
    Each environments found for Production Scheduler and ResourcePlanner will be exported in its own file in -OutDir directory.
 
    .Parameter Tenant
    The tenant name to export.
 
    .Parameter OutDir
    The root directory path to use for export. .\p1EnvExport by default.
     
    #>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string] $Tenant,
        [string] $OutDir
    )    
    Process {
        if (!(Test-Tenant $Tenant)) {
            Write-Warning "Tenant $Tenant does not exist."
            return
        }

        Write-Section "Exporting environments..."

        if ($OutDir -eq "") {
            $OutDir = ".\p1EnvExport"
        }

        if (!(Test-Path $OutDir)) {
            md $OutDir | Out-Null
        }

        $sourcePath = Get-EnvironmentsPathFromTenant $Tenant
        $sourcePath = $sourcePath + "*"
        Copy-Item -Recurse $sourcePath $OutDir
        Write-Section "Export finished"
    }
}