- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在 Runbook 中执行此代码,使用“Invoke-Command”连接到虚拟机。
$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
# Use the subscription that this Automation account is in
$null = Select-AzureRmSubscription -SubscriptionId $servicePrincipalConnection.SubscriptionID
Get-AzureRmVM | Select Name
$dcred = Get-AutomationPSCredential -Name 'myvm1creds'
Write-Output $DomainCred
$opts = New-PSSessionOption -SkipCACheck
Invoke-Command -Computername 'myVM1' -Credential $dcred -ScriptBlock {Get-Process} -SessionOption $opts
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
出现以下错误:
[myVM1] 连接到远程服务器 myVM1 失败,并显示以下错误消息:WinRM 客户端无法处理要求。如果身份验证方案与 Kerberos 不同,或者客户端计算机未加入域,那么必须使用 HTTPS 传输,或者必须将目标计算机添加到 TrustedHosts 配置设置中。使用 winrm.cmd 配置 TrustedHosts。请注意,TrustedHosts 列表中的计算机可能未经过身份验证。你可以通过运行以下命令获取更多信息:winrm help config。欲了解更多信息,请参阅about_Remote_Troubleshooting 帮助主题。 + 类别信息:OpenError:(myVM1:字符串)[],PSRemotingTransportException +FullyQualifiedErrorId:ServerNotTrusted,PSSessionStateBroken
知道需要做什么才能通过 Azure 虚拟机上的 Runbook 运行 powershell 脚本
最佳答案
在 Azure Runbook 中,我们无法使用传输 HTTP 来连接 Azure VM,因为 Azure Runbook 无法添加信任主机,因此我们需要使用 HTTPS 来连接 Azure VM。
这是我的步骤:
1.创建自签名证书。
使用makecert.exe
创建它。
2.配置Winrm监听HTTPS,在CMD中运行此脚本:
winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Port="5986" ;Hostname="jasonvm" ;CertificateThumbprint="98941E137CDF9553CCB0C28D5814EB9EDB1AC87D"}
3.在Azure NSG入站规则和Windows防火墙入站规则中添加端口5986。4.我们可以使用此 Runbook 连接 Azure VM:
$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
$null = Select-AzureRmSubscription -SubscriptionId $servicePrincipalConnection.SubscriptionID
Get-AzureRmVM | Select Name
$dcred = Get-AutomationPSCredential -Name 'jasonvm'
Write-Output $DomainCred
$opts = New-PSSession -ConnectionUri 'https://52.185.148.177:5986' -Credential $dcred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $opts -ScriptBlock {Get-Process}
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
这是我的结果:
关于powershell - 运行在虚拟机上执行 PowerShell 命令的 Azure Runbook 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45978965/
我有一个配置了混合 Runbook Worker 的自动化帐户,突然所有作业每 15 分钟就会重新启动 3 次,并最终因错误而暂停: 工作被暂停。要进行其他故障排除,请检查混合 Runbook 工作组
我有一个运行手册名称“RB_ConnectSQL” workflow RB_ConnectSQL { [OutputType([string])] param (
我对 Azure Runbook 和自动化还很陌生。 我有几个azure Sql 数据库,并且数据库中有我想按顺序运行的存储过程。在使用 On-premises SQL Server 之前,我们有一个
场景: 我有 2 个 Runbook,Runbook A 和 Runbook B。 在 Runbook B 中,我想将 Runbook A 加载到内存中。 以下运行不起作用,有人可以帮我吗? .\ru
背景 我有一个 Azure Runbook(名为 RunStoredProcedure2),定义如下: param( [parameter(Mandatory=$True)] [string] $Sq
我想使用 Runbook 删除另一个 Runbook 输出(Azure 文件共享快照)。 这可能吗?如果您知道什么,请在这里写下 运行手册 1:创建 Azure 文件共享快照 $context = N
背景: 我正在尝试通过 Azure 上的 Runbook 设置脚本。我发现不寻常的是,我可以通过 Azure Powershell Cloud Shell 运行该命令并且它可以工作。但是,当我尝试通过
我有一个每天早上运行的 Azure Runbook。 Runbook 执行“Get-AzureStorageBlob”,但由于我们在存储帐户上启用了防火墙,它现在失败并出现错误: Get-AzureS
所以我有一个运行手册,可以在周末自动关闭和启动我的 Azure VM。然后发送一封事务电子邮件,确认 VPS 已关闭/启动。 我已经如图所示设置了参数。是否有原因说明为什么它在主题行中正确说明了我的虚
我有一个处于运行状态的 PowerShell Azure Runbook。 通过 Azure 门户按“停止”会导致错误消息: "Job could not be stopped". 使用 PowerS
我在自动化帐户中使用 Azure Runbook 已经有一段时间了,但最近我的任务是确定谁在执行该 Runbook。 我注意到当您从作业中获取信息时,有一个名为“执行者”的字段,但似乎该字段已被 MS
我正在尝试设置 Powershell Runbook 来访问 Azure 资源。 我正在按照 this page 上的说明进行操作. 我已为自动化帐户分配了系统身份,但示例脚本根本不起作用。 # Si
我正在尝试设置 Powershell Runbook 来访问 Azure 资源。 我正在按照 this page 上的说明进行操作. 我已为自动化帐户分配了系统身份,但示例脚本根本不起作用。 # Si
我的自动化帐户中有一个 Azure PowerShell 7.1 Runbook,它正在按预期执行。我遇到的唯一问题是运行作业屏幕中的错误输出始终缺少详细信息列。这意味着我必须点击每条记录才能查看其中
我正在尝试运行 API 管理服务的备份。我可以在我的本地计算机上使用下面的代码在我的子所有者登录上下文中在 PS 中执行此操作,不会出现任何问题。 当我尝试将其作为 Runbook 运行时,我只会返回
我有一个 Runbook PowerShell,它会删除所有资源组及其上的所有内容,但带有 RG 的名称。有没有办法做同样的事情,但只能使用与该 RG 关联的标签?运行 Runbook 时,它不会要求
Azure 运行手册。 问题: 如何通过 Runbook 在远程 Azure VM 上运行/调用 powershell 脚本?该脚本放置在远程虚拟机上。 没有 Azure AD,powershell
我创建了一个 Runbook 来处理多维数据集的多个分区。我启动了它,3小时后,它停止了。没有错误消息或警告,输出 Pane 中也没有任何内容。我唯一的消息就是这个 异常 该作业被逐出并随后达到停止状
我无法在 Azure Runbook 中运行“Get-Azurermlog”。我收到错误“术语“Get-Azurermlog”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称”。它是一个标准
我一直在到处寻找,但我什至找不到一个简单的方法来使用 powershell 列出 Runbook...我有 4 个订阅,每个订阅中有几个自动化帐户,当我试图通过控制台浏览来查找特定的 Runbook
我是一名优秀的程序员,十分优秀!