Jaa


Opetusohjelma: ympäristön hallinnan asetusten luominen, päivittäminen ja luettelointi

Tässä opetusohjelmassa näytetään, miten ohjelmointirajapinnan Power Platform (esiversio) avulla luodaan, päivitetään ja luetteloidaan ympäristön hallinta-asetuksia.

Tässä opetusohjelmassa opit tekemään seuraavat toiminnot:

  1. Todenna API:n avulla Power Platform .
  2. Luo uusi asetusarvo.
  3. Luettele kaikki ympäristön hallinta-asetusten arvot.
  4. Päivitä asetusarvo.

Esimerkkinä tästä skenaariosta asiakas saattaa haluta ottaa käyttöön tallennuksen jaetun käytön allekirjoituksen (SAS) IP-rajoitukset ja SAS-kutsujen kirjaamisen.

Vaihe 1. Todenna käyttäen Power Platform -ohjelmointirajapintaa

Voit todentaa Power Platform -ohjelmointirajapinnan avulla seuraavan PowerShell-skriptin avulla.

Import-Module "MSAL.PS"
$AuthResult = Get-MsalToken -ClientId '<client id of your Microsoft Entra ID application registration>' -Scope 'https://api.powerplatform.com/.default'
$Headers = @{Authorization = "Bearer $($AuthResult.AccessToken)"}

Vaihe 2. Uuden asetusarvon luominen

Seuraavan PowerShell-komentosarjan avulla voit luoda uuden asetusarvon tallennuksen jaetun käytön allekirjoituksen (SAS) IP-rajoituksille sekä niihin liittyvän valvontakirjaustoiminnon. Nämä kaksi asetusta ovat poissa käytöstä, mutta päivitämme ne myöhemmin ja otamme ne käyttöön.

#Set your environment ID
$environmentId = "ENV_ID_HERE"

# Please uncomment the values that need to be updated
$EnvironmentManagementSettings = @{
    "EnableIpBasedStorageAccessSignatureRule" = $false
    "LoggingEnabledForIpBasedStorageAccessSignature" = $false
}

$body = $json = $EnvironmentManagementSettings | ConvertTo-Json

try 
{
    # Create the new setting value
    Write-Host "Invoking Create Management Setting for Environment $environmentId with body $body"
    $apiResponse = Invoke-WebRequest -Method Post -Uri "https://api.powerplatform.com/environmentmanagement/environments/$environmentId/settings/?api-version=2022-03-01-preview" -Headers $Headers -Body $body

    Write-Host "Operation Status: $apiResponse.StatusDescription"
} 
catch 
{
    # Dig into the exception to get the Response details.
    Write-Host "Response CorrelationId:" $_.Exception.Response.Headers["x-ms-correlation-id"]
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();

        Write-Host $responseBody
}

Lisätietoja ohjelmointirajapinnan viitteestä Power Platform on kohdassa Ympäristön hallinta-asetukset – Luo ympäristön hallinta-asetukset.

Vaihe 3. Luettele kaikki ympäristön hallinta-asetukset

Käytä seuraavaa PowerShell komentosarjaa luetellaksesi kaikki aiemmin luodut asetukset tälle ympäristölle.

#Set your environment ID
$environmentId = "ENV_ID_HERE"

try 
{
    # Create the new setting value
    Write-Host "Invoking List Management Settings for Environment $environmentId"
    $apiResponse = Invoke-WebRequest -Method Get -Uri "https://api.powerplatform.com/environmentmanagement/environments/$environmentId/settings/?api-version=2022-03-01-preview&$select=EnableIpBasedStorageAccessSignatureRule,LoggingEnabledForIpBasedStorageAccessSignature" -Headers $Headers

    Write-Host $apiResponse
} 
catch 
{
    # Dig into the exception to get the Response details.
    Write-Host "Response CorrelationId:" $_.Exception.Response.Headers["x-ms-correlation-id"]
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();

        Write-Host $responseBody
}

Lisätietoja ohjelmointirajapinnan viitteestä Power Platform on kohdassa Ympäristön hallinta-asetukset – Luettelo Ympäristön hallinta-asetukset.

Vaihe 4. Asetuksen arvon päivittäminen

Käytä seuraavaa PowerShell komentosarjaa päivittääksesi aiemmin määritetyn asetusarvon. Tässä vaihe otat SAS (Storage Shared Access Signature) -allekirjoituksen kirjaamisen käyttöön.

#Set your environment ID
$environmentId = "ENV_ID_HERE"

# Please uncomment the values that need to be updated
$EnvironmentManagementSettings = @{
    "LoggingEnabledForIpBasedStorageAccessSignature" = $true
}

$body = $json = $EnvironmentManagementSettings | ConvertTo-Json

try 
{
    # Updating the setting value
    Write-Host "Invoking Update Management Setting for Environment $environmentId with body $body"
    $apiResponse = Invoke-WebRequest -Method Patch -Uri "https://api.powerplatform.com/environmentmanagement/environments/$environmentId/settings/?api-version=2022-03-01-preview" -Headers $Headers -Body $body

    Write-Host "Operation Status: $apiResponse.StatusDescription"
} 
catch 
{
    # Dig into the exception to get the Response details.
    Write-Host "Response CorrelationId:" $_.Exception.Response.Headers["x-ms-correlation-id"]
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($result)
        $reader.BaseStream.Position = 0
        $reader.DiscardBufferedData()
        $responseBody = $reader.ReadToEnd();

        Write-Host $responseBody
}

Lisätietoja ohjelmointirajapinnan viitteestä Power Platform on kohdassa Ympäristön hallinta-asetukset – Päivitä ympäristön hallinta-asetukset.

Ympäristön hallinnan asetukset