Public/Invoke-ClearEnvironmentCache.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function Invoke-CleanEnvironmentCache {
    [CmdLetBinding()]
    param (
        [string] $EnvironmentName = $env:SC_Environment,
        [string] $EngineHost = $env:SC_EngineHost,
        [int] $EnginePort = $env:SC_EnginePort
    )

    $Url = ("https://{0}:{1}/commerceops/ClearEnvironmentCache()" -f $EngineHost, $EnginePort)
    Write-Verbose "Calling: $($Url)" 

    $token = Get-IdServerTokenFromEnvironment

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", $token)
    $headers.Add("Content-Type", "application/json")

    $body = "{`"environmentName`": `"$EnvironmentName`"}"

    try {
        $result = Invoke-RestMethod $Url -TimeoutSec 1200 -Method POST -Headers $headers -Body $body 
        $result
    } catch {
        Write-Host "Code:" $_.Exception.Response.StatusCode.value__ 
        Write-Host "Description:" $_.Exception.Response.StatusDescription
    }
    
    Write-Verbose "Clean environment cache" 
}