共用方式為


Runbook - Get Content

擷取 Runbook 名稱所識別的 Runbook 內容。

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/content?api-version=2023-11-01

URI 參數

名稱 位於 必要 類型 Description
automationAccountName
path True

string

自動化帳戶的名稱。

resourceGroupName
path True

string

Azure 資源群組的名稱。

Regex 模式: ^[-\w\._]+$

runbookName
path True

string

Runbook 名稱。

Regex 模式: ^[a-zA-Z][a-zA-Z-_0-9]*$

subscriptionId
path True

string

取得用來唯一識別 Microsoft Azure 訂用帳戶的訂用帳戶認證。 訂用帳戶識別碼會構成每個服務呼叫 URI 的一部分。

api-version
query True

string

用戶端 API 版本。

回應

名稱 類型 Description
200 OK

file

確定

Media Types: "text/powershell"

Other Status Codes

ErrorResponse

描述作業失敗原因的自動化錯誤回應。

Media Types: "text/powershell"

安全性

azure_auth

Azure Active Directory OAuth2 Flow

類型: oauth2
Flow: implicit
授權 URL: https://login.microsoftonline.com/common/oauth2/authorize

範圍

名稱 Description
user_impersonation 模擬您的用戶帳戶

範例

Get runbook content

範例要求

GET https://management.azure.com/subscriptions/subid/resourceGroups/rg/providers/Microsoft.Automation/automationAccounts/ContoseAutomationAccount/runbooks/Get-AzureVMTutorial/content?api-version=2023-11-01

範例回覆

Content-Type: text/powershell
"<#\r\n    .DESCRIPTION\r\n        An example runbook which prints out the first10 Azure VMs in your subscription (ordered alphabetically).\r\n        For more information about how this runbook authenticates to your Azure subscription, see our documentation here: http: //aka.ms/fxu3mn\r\n\r\n    .NOTES\r\n        AUTHOR: Azure Automation Team\r\n        LASTEDIT: Mar27,\r\n            2015\r\n#>\r\nworkflow Get-AzureVMTutorial{\r\n    #The name of the Automation Credential Asset this runbook will use to authenticate to Azure.\r\n    $CredentialAssetName = 'DefaultAzureCredential'\r\n\r\n    #Get the credential with the above name from the Automation Asset store\r\n    $Cred = Get-AutomationPSCredential -Name $CredentialAssetName\r\n    if(!$Cred){\r\n        Throw\"Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account.\"\r\n                }\r\n\r\n    #Connect to your Azure Account\r\n    $Account = Add-AzureAccount -Credential $Cred\r\n    if(!$Account){\r\n        Throw\"Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct.\"\r\n                }\r\n\r\n    #TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.\r\n    #Select-AzureSubscription -SubscriptionName\"TODO: your Azure subscription name here\"\r\n    \r\n    #Get all the VMs you have in your Azure subscription\r\n    $VMs = Get-AzureVM\r\n\r\n    #Print out up to10 of those VMs\r\n    if(!$VMs){\r\n        Write-Output\"No VMs were found in your subscription.\"\r\n                } else{\r\n        Write-Output $VMs[0..9\r\n                    ]\r\n                }\r\n            }"

定義

ErrorResponse

作業失敗的錯誤回應

名稱 類型 Description
code

string

錯誤碼

message

string

錯誤訊息,指出作業失敗的原因。