Public/Get-P1Environments.ps1

function Get-P1Environments {
    <#
    .Synopsis
    Get PlannerOne environments.
 
    .Description
    Return the PlannerOne environments informations
 
    .Parameter Product
    The PlannerOne product (Project or Production).
 
    .Parameter Tenant
    The PlannerOne tenant.
     
    .Parameter WebPort
    The PlannerOne web application port.
 
    .Parameter WebAppName
    The PlannerOne web application name.
 
    .Example
    # Get the list of environments using a tenant
    Get-P1Environments -Product "Project" -Tenant "PlannerOneProd" -WebPort 80
 
    .Example
    # Get the list of environments using the WebAppName
    Get-P1Environments -Product "Project" -WebPort 80 -WebAppName "PlannerOneDev"
    #>

    [cmdletbinding()]
    param( 
        [Parameter(Mandatory=$true)]
        [string] $Product,
        [int] $WebPort,
        [string] $Tenant,
        [string] $WebAppName
    )
    Process
    {
    
    if (!(Test-Tenant $Tenant)) {
        Write-Warning "Tenant $Tenant does not exist."
        Write-Warning "Operation canceled."
        return;
    }

    $TenantInfo = Get-P1Tenant $Tenant

    if ($WebPort -eq 0) {
        $WebPort = $TenantInfo.SitePort
    }
        
    if (!$WebAppName) {
        $WebAppName = $TenantInfo.WebApplicationName
    }

    $url = "http://localhost:$WebPort/$WebAppName/configure/ConfigurationService.svc/environments/" + $Product

    $conf = Invoke-RestMethod -Method GET -Uri $url -ContentType "application/json" -UseDefaultCredentials
    $objEnv = $conf | ConvertFrom-Json
    $environments = @()
    for($i=0; ($i -le $objEnv.Length); $i++)
    {
        $environments += $objEnv[$i].Value
    }

    return $environments
    }
}