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

Virtual Machine Run Commands - Get

获取位置中订阅的特定运行命令。

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/runCommands/{commandId}?api-version=2025-04-01

URI 参数

名称 必需 类型 说明
commandId
path True

string

指定预定义内置脚本的 commandId。 可用于 Linux 的命令 ID 列在 、 Windows 中https://aka.ms/RunCommandManagedLinux#available-commandshttps://aka.ms/RunCommandManagedWindows#available-commands

location
path True

string

minLength: 1

Azure 区域的名称。

subscriptionId
path True

string

minLength: 1

目标订阅的 ID。

api-version
query True

string

minLength: 1

要用于此操作的 API 版本。

响应

名称 类型 说明
200 OK

RunCommandDocument

Azure作已成功完成。

Media Types: "application/json", "text/json"

Other Status Codes

CloudError

意外错误响应。

Media Types: "application/json", "text/json"

安全性

azure_auth

Azure Active Directory OAuth2 Flow。

类型: oauth2
流向: implicit
授权 URL: https://login.microsoftonline.com/common/oauth2/authorize

作用域

名称 说明
user_impersonation 模拟用户帐户

示例

VirtualMachineRunCommandGet

示例请求

GET https://management.azure.com/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/providers/Microsoft.Compute/locations/SoutheastAsia/runCommands/RunPowerShellScript?api-version=2025-04-01

示例响应

{
  "script": [
    "param(",
    "    [string]$arg1,",
    "    [string]$arg2",
    ")",
    "Write-Host This is a sample script with parameters $arg1 $arg2"
  ],
  "parameters": [
    {
      "name": "arg1",
      "type": "string",
      "defaultValue": "value1"
    },
    {
      "name": "arg2",
      "type": "string",
      "defaultValue": "value2"
    }
  ],
  "$schema": "http://schema.management.azure.com/schemas/2016-11-17/runcommands.json",
  "id": "RunPowerShellScript",
  "osType": "Windows",
  "label": "Executes a PowerShell script",
  "description": "Custom multiline PowerShell script should be defined in script property. Optional parameters can be set in parameters property."
}

定义

名称 说明
ApiError

API 错误。

ApiErrorBase

Api 错误库。

CloudError

来自计算服务的错误响应。

InnerError

内部错误详细信息。

OperatingSystemTypes

此属性允许指定从用户映像或专用 VHD 创建 VM 时磁盘中包含的 OS 类型。 可能的值包括:Windows、Linux。

RunCommandDocument

描述运行命令的属性。

RunCommandParameterDefinition

描述运行命令参数的属性。

ApiError

API 错误。

名称 类型 说明
code

string

错误代码。

details

ApiErrorBase[]

Api 错误详细信息

innererror

InnerError

Api 内部错误

message

string

错误消息。

target

string

特定错误的目标。

ApiErrorBase

Api 错误库。

名称 类型 说明
code

string

错误代码。

message

string

错误消息。

target

string

特定错误的目标。

CloudError

来自计算服务的错误响应。

名称 类型 说明
error

ApiError

API 错误。

InnerError

内部错误详细信息。

名称 类型 说明
errordetail

string

内部错误消息或异常转储。

exceptiontype

string

异常类型。

OperatingSystemTypes

此属性允许指定从用户映像或专用 VHD 创建 VM 时磁盘中包含的 OS 类型。 可能的值包括:Windows、Linux。

说明
Windows
Linux

RunCommandDocument

描述运行命令的属性。

名称 类型 说明
$schema

string

VM 运行命令架构。

description

string

VM 运行命令说明。

id

string

VM 运行命令 ID。

label

string

VM 运行命令标签。

osType

OperatingSystemTypes

操作系统类型。

parameters

RunCommandParameterDefinition[]

脚本使用的参数。

script

string[]

要执行的脚本。

RunCommandParameterDefinition

描述运行命令参数的属性。

名称 类型 说明
defaultValue

string

运行命令参数默认值。

name

string

run 命令参数名称。

required

boolean

需要运行命令参数。

type

string

run 命令参数类型。