教程:创建、更新和列出环境管理设置(预览版)
[本文为预发布文档,可能会发生变化。]
本教程演示如何使用 Power Platform API(预览版)创建、更新和列出环境管理设置。
在本教程中,您将学习如何:
例如,客户可能希望启用 存储共享访问签名(SAS)IP 限制 和 SAS 调用日志记录。
重要提示
- 这是一项预览功能。
- 预览功能不适合生产使用且功能可能受限。 这些功能在正式发布之前推出,以便客户可以提前使用并提供反馈。
步骤 1. 使用 Power Platform API 进行身份验证
使用以下 PowerShell 脚本通过 Power Platform API 进行身份验证。
Import-Module "MSAL.PS"
$AuthResult = Get-MsalToken -ClientId '49676daf-ff23-4aac-adcc-55472d4e2ce0' -Scope 'https://api.powerplatform.com/.default'
$Headers = @{Authorization = "Bearer $($AuthResult.AccessToken)"}
步骤 2. 创建新的设置值
使用以下 PowerShell 脚本为存储共享访问签名(SAS)IP 限制和相关的审核日志记录功能创建新的设置值。 这两个设置处于关闭状态,但是,我们稍后将更新它们以将其打开。
#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
}
Power Platform 有关 环境管理设置 - 创建环境管理设置中的 API 参考的更多信息。
步骤 3. 列出环境的所有管理设置
使用以下 PowerShell 脚本列出之前为此环境创建的所有设置。
#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
}
Power Platform 在环境管理设置 - 列出环境管理设置 中了解有关 API 参考的更多信息。
步骤 4. 更新设置值
使用以下 PowerShell 脚本更新以前定义的设置值。 在本步骤中,您将打开存储共享访问签名(SAS)的日志记录。
#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
}
Power Platform 有关 环境管理设置 - 更新环境管理设置中的 API 参考的更多信息。