使用 Azure 自动化开发 PowerShell 脚本可能会非常缓慢。这可以通过使用 PowerShell ISE 插件来帮助实现,该插件允许您在本地测试运行脚本。
但是,在本地运行与在 Azure 自动化中运行时,某些事情不可避免地会有所不同。例如文件路径。
检测脚本当前运行的环境的正确方法是什么?
目前我定义了一个变量资产,我只保留本地而不上传。然后我可以执行以下操作:
# Check if we are running locally - NOTE: Do not upload the runningLocally variable! Keep it local only
if (Get-AutomationVariable -Name 'runningLocally') {
# We are running locally
} else {
# We are running in Azure Automation
}
Run Code Online (Sandbox Code Playgroud)
但这似乎相当笨拙且容易出错。我正在寻找一种更强大和可靠的方法。
我发现了一些额外的方法。AA运行时的机器名和用户名都是“客户端”,这似乎是一个更健壮的方法?
我正在使用天蓝色的手臂模板在天蓝色中创建一个Web应用程序.现在我需要在将使用此模板创建的webapps中安装New Relic Extension.所以我无法找到具体的json格式.请帮帮我!
azure azure-web-sites azure-resource-manager azure-automation
有谁知道如何在作为 powershell 工作流运行的 azure 工作簿中隐藏命令 Select-AzureRmSubscription 的输出
谢谢
我对这个问题深感震惊。我请求您回答或给予提示。我已经没有选择了。
我通过 WebHook 在 CPU 利用率较高时调用 azure runbook。我的问题是 Runbook 内部数据未正确解码。例如,下面的行不打印任何内容。
Write-Output $WebHookData.RequestHeader
Run Code Online (Sandbox Code Playgroud)
如果我尝试将数据显式转换为 JSON,就像这样
*$WebhookData = ConvertFrom-Json $WebhookData*
Run Code Online (Sandbox Code Playgroud)
那么这是一个投掷错误。
ConvertFrom-Json:无效的 JSON 原语:。在行:6 字符:31 + $WebhookData = $WebhookData | 从 Json 转换
顺便说一句,我正在尝试使用 Azure 库上提供的 Runbook {使用 Azure 自动化垂直扩展 Azure 资源管理器 VM}
我的 Webhook 是从虚拟机上创建的警报调用的。
一个非常奇怪的观察:
工作 WebHood 示例(在示例中找到) {"WebhookName":"test1","RequestBody":" [ \r\n {\r\n \"Message\": \"Test Message\"\r\n } \r\n****]****"
不工作(从虚拟机调用 Runbook 时发送的数据):
{"WebhookName":"test2","RequestBody":" { \"schemaId\":\"AzureMonitorMetricAlert\" } }
谢谢
powershell webhooks azure-autoscaling-block azure-automation azure-runbook
以下 az-cli 命令不支持 azure 应用服务上的自动缩放实例的指标。
# Create cpu autoscale rule
az monitor autoscale rule create --resource-group $COMMON_RESOURCE_GROUP_NAME \
--subscription $SUBSCRIPTION_ID \
--resource $WEBAPP_NAME \
--resource-type 'Microsoft.Web/sites' \
--autoscale-name "test" \
--condition "Percentage CPU > 75 avg 5m" \
--scale out 1
Run Code Online (Sandbox Code Playgroud)
响应 - 引发“Microsoft.WindowsAzure.Management.Monitoring.MonitoringServiceException”类型的异常。 [代码:“UnsupportedMetric”]
我遵循了此 Microsoft 文档 - https://learn.microsoft.com/en-us/cli/azure/monitor/autoscale/rule?view=azure-cli-latest
我知道如何通过天蓝色门户进行自动缩放,但我想使用脚本来执行此操作。
azure azure-automation azure-app-service-envrmnt azure-web-app-service
如何传递具有以下消息的异常?
Invoke-RestMethod:{"Message":"ETag不代表资源的最新状态."}
看到参考,我认为"传递If-Match: "*" header"应该是关键,但不知道如何做到这一点.
注意:更新或删除文件时,将应用ETag行为.您可以传递If-Match:"*"标头以禁用ETag检查.
# Kudu auth information creation
$WebSiteName = Get-AutomationVariable -Name 'WebApps_name'
# Example: "WebApps04"
$username = Get-AutomationVariable -Name 'WebApps_deploy_username'
$password = Get-AutomationVariable -Name 'WebApps_deploy_password'
# Above are set by "Asset - Variable" of in Azure Automation account
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$userAgent = "powershell/1.0"
# Add-content dummy HTML file
$Filename = "sample1.html"
$a = "<HTML><BODY>Sample HTML Data " + $WebSiteName + "</BODY></HTML>"
$a | add-content …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Set-AzureRmAppServicePlan. 我连接正常,可以列出帐户中的所有资源,但是在调用应用程序计划方法时,没有找到。这里错过了什么?
代码:
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Select-AzureRmSubscription -SubscriptionId "MYSUB"
Set-AzureRmAppServicePlan -Name "my-plan" -ResourceGroupName "my-group" -Tier "Standard" -WorkerSize "Small"
Run Code Online (Sandbox Code Playgroud)
错误:
Set-AzureRmAppServicePlan : The term 'Set-AzureRmAppServicePlan' is not recognized as …Run Code Online (Sandbox Code Playgroud) 我完全没有使用 PowerShell 的经验 - 我想要做的是使用我的 Azure 自动化服务来设置一个 Runbook,它会在每晚凌晨 1 点自动重新启动我的一个 Azure Web 应用程序。
是否可以使用 Powershell/Azure 自动化来完成此操作?
我对自动化是全新的,对 Powershell 也很陌生,所以我希望这是一个简单的修复。:)
我正在尝试让一些代码运行。据我所知,它确实运行了,但测试窗格没有显示任何内容。基于此线程:Azure powershell runbook do not show any output,我确实尝试重新发布代码并清除浏览器缓存,但这对我的情况没有帮助,所以我认为代码存在问题?
这是我的(通用)代码):
workflow DB_DailyTasks
{
Write-Output "Code starting"
inlinescript
{
[string] $SqlServerName = "myDb.database.windows.net"
$Credential = Get-AutomationPSCredential -Name "myDatabase-automation"
# Setup credentials
$ServerName = $Using:SqlServerName
$UserId = $Using:Credential.UserName
$Password = ($Using:Credential).GetNetworkCredential().Password
# Execute the udp_myProc procedure
# Create connection for each individual database
$DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$DatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
Write-Output "ConnectionState is: $(DatabaseConnection.State)"
$DbName = "myDb"
# Setup connection string for $DbName
$DatabaseConnection.ConnectionString = "Server=$ServerName; Database=$DbName; …Run Code Online (Sandbox Code Playgroud) 我在 Azure 的同一区域中有一个 Log Analytics 工作区“demo-law-sea”和一个自动化帐户“demo-aa-sea”。我想创建“在非工作时间启动/停止虚拟机”。
它请求 Log Analytics 工作区和自动化帐户。我只是选择“demo-law-sea”,但我不能选择“demo-aa-sea”,因为它们没有链接。
然后,我转到 Log Analytics 工作区和自动化帐户,看看是否可以将它们链接在一起。任一者都有相关资源来引用另一者,但他们只有取消链接按钮而没有链接。
要继续,我在创建“在非工作时间启动/停止 VM”时使用选定的 Log Analytics 工作区创建一个新的自动化帐户,然后删除现有的自动化帐户“demo-aa-sea”。
有没有办法链接现有的日志分析工作区和自动化帐户?有什么先决条件吗?谢谢。