你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

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>]

说明

仅构造和执行对 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": {}
             }

按路径获取 Log Analytics 工作区。 它仅支持管理平面 API,Azure 资源管理器的主机名根据 Azure 环境设置添加。

示例 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图形 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 的路径。 不应添加资源管理器的主机名。

类型: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 资源管理器的资源 ID。

类型:Uri
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-ResourceProviderName

目标资源提供程序名称

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-ResourceType

目标资源类型列表

类型:String[]
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-SubscriptionId

目标订阅 ID

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Uri

Azure 资源的统一资源标识符。 目标资源需要支持 Azure AD 身份验证,访问令牌是根据资源 ID 派生的。如果未设置资源 ID,则根据当前 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