共用方式為


Invoke-AzRestMethod

建構和執行對 Azure 資源管理端點的 HTTP 要求

語法

Invoke-AzRestMethod
      -Path <String>
      [-Method <String>]
      [-Payload <String>]
      [-AsJob]
      [-WaitForCompletion]
      [-PollFrom <String>]
      [-FinalResultFrom <String>]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-AzRestMethod
      [-SubscriptionId <String>]
      [-ResourceGroupName <String>]
      [-ResourceProviderName <String>]
      [-ResourceType <String[]>]
      [-Name <String[]>]
      -ApiVersion <String>
      [-Method <String>]
      [-Payload <String>]
      [-AsJob]
      [-WaitForCompletion]
      [-PollFrom <String>]
      [-FinalResultFrom <String>]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-AzRestMethod
      [-Uri] <Uri>
      [-ResourceId <Uri>]
      [-Method <String>]
      [-Payload <String>]
      [-AsJob]
      [-WaitForCompletion]
      [-PollFrom <String>]
      [-FinalResultFrom <String>]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

建構和執行對 Azure 資源管理端點的 HTTP 要求

範例

範例 1

Invoke-AzRestMethod -Path "/subscriptions/{subscription}/resourcegroups/{resourcegroup}/providers/microsoft.operationalinsights/workspaces/{workspace}?api-version={API}" -Method GET

Headers    : {[Cache-Control, System.String[]], [Pragma, System.String[]], [x-ms-request-id, System.String[]], [Strict-Transport-Security, System.String[]]…}
Version    : 1.1
StatusCode : 200
Method     : GET
Content    : {
               "properties": {
                 "source": "Azure",
                 "customerId": "{customerId}",
                 "provisioningState": "Succeeded",
                 "sku": {
                   "name": "pergb2018",
                   "maxCapacityReservationLevel": 3000,
                   "lastSkuUpdate": "Mon, 25 May 2020 11:10:01 GMT"
                 },
                 "retentionInDays": 30,
                 "features": {
                   "legacy": 0,
                   "searchVersion": 1,
                   "enableLogAccessUsingOnlyResourcePermissions": true
                 },
                 "workspaceCapping": {
                   "dailyQuotaGb": -1.0,
                   "quotaNextResetTime": "Thu, 18 Jun 2020 05:00:00 GMT",
                   "dataIngestionStatus": "RespectQuota"
                 },
                 "enableFailover": false,
                 "publicNetworkAccessForIngestion": "Enabled",
                 "publicNetworkAccessForQuery": "Enabled",
                 "createdDate": "Mon, 25 May 2020 11:10:01 GMT",
                 "modifiedDate": "Mon, 25 May 2020 11:10:02 GMT"
               },
               "id": "/subscriptions/{subscription}/resourcegroups/{resourcegroup}/providers/microsoft.operationalinsights/workspaces/{workspace}",
               "name": "{workspace}",
               "type": "Microsoft.OperationalInsights/workspaces",
               "location": "eastasia",
               "tags": {}
             }

依路徑取得記錄分析工作區。 它僅支援管理平面 API,並根據 Azure 環境設定新增 Azure Resource Manager 的主機名。

範例 2

Invoke-AzRestMethod https://graph.microsoft.com/v1.0/me

Headers    : {[Date, System.String[]], [Cache-Control, System.String[]], [Transfer-Encoding, System.String[]], [Strict-Transport-Security, System.String[]]…}
Version    : 1.1
StatusCode : 200
Method     : GET
Content    : {"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity","businessPhones":["......}

透過 MicrosoftGraph API 取得目前登入的使用者。 這個範例相當於 Get-AzADUser -SignedIn

範例 3

$subscriptionId = (Get-AzContext).Subscription.ID
Invoke-AzRestMethod -SubscriptionId $subscriptionId -ResourceGroupName "test-group" -ResourceProviderName Microsoft.AppPlatform -ResourceType Spring,apps -Name "test-spring-service" -ApiVersion 2020-07-01 -Method GET

Headers    : {[Cache-Control, System.String[]], [Pragma, System.String[]], [Vary, System.String[]], [x-ms-request-id,
             System.String[]]…}
Version    : 1.1
StatusCode : 200
Method     : GET
Content    : {"value":[{"properties":{"public":true,"url":"https://test-spring-service-demo.azuremicroservices.io","provisioni
             ngState":"Succeeded","activeDeploymentName":"default","fqdn":"test-spring-service.azuremicroservices.io","httpsOn
             ly":false,"createdTime":"2022-06-22T02:57:13.272Z","temporaryDisk":{"sizeInGB":5,"mountPath":"/tmp"},"pers
             istentDisk":{"sizeInGB":0,"mountPath":"/persistent"}},"type":"Microsoft.AppPlatform/Spring/apps","identity
             ":null,"location":"eastus","id":"/subscriptions/$subscriptionId/resourceGroups/test-group/providers/Microsoft.AppPlatform/Spring/test-spring-service/apps/demo","name":"demo"},{"properties":{"publ
             ic":false,"provisioningState":"Succeeded","activeDeploymentName":"deploy01","fqdn":"test-spring-service.azuremicr
             oservices.io","httpsOnly":false,"createdTime":"2022-06-22T07:46:54.9Z","temporaryDisk":{"sizeInGB":5,"moun
             tPath":"/tmp"},"persistentDisk":{"sizeInGB":0,"mountPath":"/persistent"}},"type":"Microsoft.AppPlatform/Sp
             ring/apps","identity":null,"location":"eastus","id":"/subscriptions/$subscriptionId/r
             esourceGroups/test-group/providers/Microsoft.AppPlatform/Spring/test-spring-service/apps/pwsh01","name":"pwsh0
             1"}]}

列出 Spring 服務 「test-spring-service」 底下的應用程式

範例 4

$subscriptionId = (Get-AzContext).Subscription.ID
Invoke-AzRestMethod -SubscriptionId $subscriptionId -ResourceGroupName "test-group" -ResourceProviderName Microsoft.AppPlatform -ResourceType Spring -Name "test-spring-service","demo" -ApiVersion 2020-07-01 -Method GET

Headers    : {[Cache-Control, System.String[]], [Pragma, System.String[]], [Vary, System.String[]], [x-ms-request-id,
             System.String[]]…}
Version    : 1.1
StatusCode : 200
Method     : GET
Content    : {"properties":{"public":true,"url":"https://test-spring-service-demo.azuremicroservices.io","provisioningState":"
             Succeeded","activeDeploymentName":"default","fqdn":"test-spring-service.azuremicroservices.io","httpsOnly":false,
             "createdTime":"2022-06-22T02:57:13.272Z","temporaryDisk":{"sizeInGB":5,"mountPath":"/tmp"},"persistentDisk
             ":{"sizeInGB":0,"mountPath":"/persistent"}},"type":"Microsoft.AppPlatform/Spring/apps","identity":null,"lo
             cation":"eastus","id":"/subscriptions/$subscriptionId/resourceGroups/test-group/pr
             oviders/Microsoft.AppPlatform/Spring/test-spring-service/apps/demo","name":"demo"}

在 Spring 雲端服務 “test-spring-service” 下取得應用程式「示範」

範例 5

# Replace *** with real values
$payload = @{principalId="***"; resourceId="***"; appRoleId="***"} | ConvertTo-Json -Depth 3
Invoke-AzRestMethod -Method POST -Uri https://graph.microsoft.com/v1.0/servicePrincipals/***/appRoleAssignedTo -Payload $payload

呼叫 Microsoft Graph API,藉由建構哈希表、轉換成 JSON 字串,以及將承載傳遞至 Invoke-AzRestMethod來指派應用程式角色。

範例 5

# This example demonstrates creating or updating a resource with a long-running PUT request.
Invoke-AzRestMethod -Method PUT -Uri "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.KeyVault/managedHSMs/{hsm-name}?api-version=2023-07-01" `
  -Payload (@{
    location = "eastus"; 
    properties = @{
      softDeleteRetentionDays = 7;
      tenantId = "{tenant-id}";
      initialAdminObjectIds = @("{admin-object-id}")
    }; 
    sku = @{
      name = "Standard_B1";
      family = "B"
    } 
  } | ConvertTo-Json -Depth 10) `
  -WaitForCompletion

StatusCode : 200
Content    : {
               "sku": {
                 "family": "B",
                 "name": "Standard_B1"
               },
               "id": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.KeyVault/managedHSMs/{hsm-name}",
               "name": "{hsm-name}",
               "type": "Microsoft.KeyVault/managedHSMs",
               "location": "{region}",
               "tags": {},
               "systemData": {
                 "createdBy": "{user-email}",
                 "createdByType": "User",
                 "createdAt": "2024-10-29T05:05:49.229Z",
                 "lastModifiedBy": "{user-email}",
                 "lastModifiedByType": "User",
                 "lastModifiedAt": "2024-10-29T05:05:49.229Z"
               },
               "properties": {
                 "tenantId": "{tenant-id}",
                 "hsmUri": "https://{hsm-name}.managedhsm.azure.net/",
                 "initialAdminObjectIds": [
                   "{admin-object-id}"
                 ],
                 "enableSoftDelete": true,
                 "softDeleteRetentionInDays": 90,
                 "enablePurgeProtection": false,
                 "provisioningState": "Succeeded",
                 "statusMessage": "The Managed HSM is provisioned and ready to use.",
                 "networkAcls": {
                   "bypass": "AzureServices",
                   "defaultAction": "Allow",
                   "ipRules": [],
                   "virtualNetworkRules": []
                 },
                 "publicNetworkAccess": "Enabled",
                 "regions": [],
                 "securityDomainProperties": {
                   "activationStatus": "NotActivated",
                   "activationStatusMessage": "Your HSM has been provisioned, but cannot be used for cryptographic operations until it is activated. To activate the HSM, download the security domain."
                 }
               }
             }
Headers    : {
               "Cache-Control": "no-cache",
               "Pragma": "no-cache",
               "x-ms-client-request-id": "{client-request-id}",
               "x-ms-keyvault-service-version": "1.5.1361.0",
               "x-ms-request-id": "{request-id}",
               "x-ms-ratelimit-remaining-subscription-reads": "249",
               "x-ms-ratelimit-remaining-subscription-global-reads": "3749",
               "x-ms-correlation-request-id": "{correlation-request-id}",
               "x-ms-routing-request-id": "{routing-request-id}",
               "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
               "Date": "Tue, 29 Oct 2024 05:18:44 GMT"
             }
Method     : GET
RequestUri : https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.KeyVault/managedHSMs/{hsm-name}?api-version=2023-07-01
Version    : 1.1

傳送長時間執行的 PUT 要求,以在 Azure 中建立或更新受控 HSM 資源,並在作業需要完成之前輪詢。 此範例使用佔位符 ({subscription-id}、{resource-group}、{hsm-name}、{tenant-id}和 {admin-object-id}),使用者應該以其特定值取代。

參數

-ApiVersion

Api 版本

類型:String
Position:Named
預設值:None
必要:True
接受管線輸入:False
接受萬用字元:False

-AsJob

在背景執行 Cmdlet

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Confirm

在執行 Cmdlet 之前,提示您進行確認。

類型:SwitchParameter
別名:cf
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-DefaultProfile

用於與 Azure 通訊的認證、帳戶、租用戶和訂用帳戶。

類型:IAzureContextContainer
別名:AzContext, AzureRmContext, AzureCredential
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-FinalResultFrom

指定長時間執行作業完成之後最終 GET 結果的標頭。

類型:String
接受的值:FinalStateVia, Location, OriginalUri, Operation-Location
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Method

Http 方法

類型:String
接受的值:GET, POST, PUT, PATCH, DELETE
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Name

目標資源名稱的清單

類型:String[]
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Path

目標資源 URL 的路徑。 不應新增 Resource Manager 的主機名。

類型:String
Position:Named
預設值:None
必要:True
接受管線輸入:False
接受萬用字元:False

-Payload

JSON 格式承載

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-PollFrom

指定長時間執行作業狀態的輪詢標頭(要從中擷取)。

類型:String
接受的值:AzureAsyncLocation, Location, OriginalUri, Operation-Location
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-ResourceGroupName

目標資源組名

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-ResourceId

您要呼叫的 REST API 所指定的識別碼 URI。 它不應該是 Azure Resource Manager 的資源識別碼。

類型:Uri
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-ResourceProviderName

目標資源提供者名稱

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-ResourceType

目標資源類型清單

類型:String[]
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-SubscriptionId

目標訂用帳戶標識碼

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Uri

Azure 資源的統一資源標識符。 目標資源需要支援 Azure AD 驗證,且存取令牌會根據資源標識符來衍生。如果未設定資源標識碼,則會根據目前 Azure 環境中的內建服務後綴來衍生其值。

類型:Uri
Position:1
預設值:None
必要:True
接受管線輸入:False
接受萬用字元:False

-WaitForCompletion

等候長時間執行的作業完成,再傳回結果。

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-WhatIf

顯示 Cmdlet 執行時會發生什麼事。 Cmdlet 未執行。

類型:SwitchParameter
別名:wi
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

輸入

System.string

輸出

PSHttpResponse