Public/Initialize-P1Environments.ps1
function Initialize-P1Environments { <# .Synopsis Initialize PlannerOne environments .Description Initialize PlannerOne environments .Parameter Environments The PlannerOne environments list to initialized. .Parameter Tenant The PlannerOne tenant. .Parameter WebPort The PlannerOne web application port. .Parameter WebAppName The PlannerOne web application name. .Example # Initialize all environments in $env array Initialize-P1Environments -Environments $env -WebPort 80 -WebAppName "PlannerOneDev" #> [cmdletbinding()] param( [Parameter(Mandatory=$true)] [object] $Environments, [Parameter(Mandatory=$true)] [int] $WebPort, [string] $Tenant, [string] $WebAppName ) Process { if ($WebPort -eq 0) { $WebPort = $DefaultWebPort } if (!$WebAppName) { $WebAppName = Get-WebAppNameFromTenant $Tenant } $url = "http://localhost:$Port/$WebAppName/configure/ConfigurationService.svc/environments/init" for($i=0; ($i -le $Environments.Length); $i++) { if ($Environments[$i].EnabledInErp -and !$Environments[$i].IsInPlannerOne) { If ($Environments[$i].EnvironmentId.Kind -eq 2) { $Product = "Project" } ElseIf ($Environments[$i].EnvironmentId.Kind -eq 1) { $Product = "Production" } $encapsulate = $Environments[$i].EnvironmentId | ConvertTo-Json -Compress $body = @{ environmentId = @{JsonValue = $encapsulate}; product = $Product; } Write-Host ("Initializing " + $Environments[$i].EnvironmentId + "...") Invoke-RestMethod -Method POST -Body ($body | ConvertTo-Json -Compress) -Uri $url -ContentType "application/json" -UseDefaultCredentials $progres = 0 Do { Start-Sleep -Milliseconds 1000 $urlProgress = "http://localhost:$Port/$WebAppName/configure/ConfigurationService.svc/progress/" + $Product $progres = Invoke-RestMethod -Method GET -Uri $urlProgress -ContentType "application/json" -UseDefaultCredentials Write-Progress -activity "Initializing in Progress" -status "$progres% Complete:" -percentcomplete $progres } While ($progres -le 99) } } } } |