Public/Import-P1Environment.ps1

function Import-P1Environment {
    <#
    .Synopsis
    Import PlannerOne environment from file.
 
    .Description
    Import an existing and initialized environment saved in file system.
    Each environments found for Production Scheduler and ResourcePlanner will be imported.
 
    .Parameter Tenant
    The tenant name to import to.
 
    .Parameter InDir
    The root directory path to use for import. Default current.
     
    #>

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

        Write-Section "Importing environments..."

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

        if (!(Test-Path $InDir)) {
            Write-Warning "Source directory does not exist"
            return
        }

        $targetPath = Get-EnvironmentsPathFromTenant $Tenant
        if (!(Test-Path $targetPath)) {
            mkdir $targetPath | Out-Null
        }

        $sourcePath = $InDir + "\*"
        Copy-Item -Recurse $sourcePath $targetPath -Force
        Write-Section "Import finished"
    }
}