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

Invoke-AzRestMethod

仅构造和执行对 Azure 资源管理终结点的 HTTP 请求

语法

Invoke-AzRestMethod
      -Path <String>
      [-Method <String>]
      [-Payload <String>]
      [-AsJob]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-AzRestMethod
      [-SubscriptionId <String>]
      [-ResourceGroupName <String>]
      [-ResourceProviderName <String>]
      [-ResourceType <String[]>]
      [-Name <String[]>]
      -ApiVersion <String>
      [-Method <String>]
      [-Payload <String>]
      [-AsJob]
      [-DefaultProfile <IAzureContextContainer>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Invoke-AzRestMethod
      [-Uri] <Uri>
      [-ResourceId <Uri>]
      [-Method <String>]
      [-Payload <String>]
      [-AsJob]
      [-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 工作区。 它仅支持 Azure 资源管理器的管理平面 API 和主机名,根据 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

通过构造哈希表、转换为 JSON 字符串并将有效负载 Invoke-AzRestMethod传递给 来调用 Microsoft 图形 API 来分配应用角色。

参数

-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

-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

-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

-WhatIf

显示运行该 cmdlet 时会发生什么情况。 cmdlet 未运行。

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

输入

System.string

输出

PSHttpResponse