我试图在Runbook中使用“Invoke-Command”连接到VM来执行此代码。运行在虚拟机上执行PowerShell命令的Azure Runbook时出现错误
$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帮助主题。 + CategoryInfo:OpenError:(myVM1:字符串)[],PSRemotingTransportException + FullyQualifiedErrorId:ServerNotTrusted,PSSessionStateBroken
任何想法什么都要做,以通过运行手册在Azure上运行PowerShell脚本虚拟机
[连接到远程服务器中使用WinRM的从PowerShell的失败(HTTPS的可能重复: //stackoverflow.com/questions/16010091/connecting-to-remote-server-failed-using-winrm-from-powershell)。 – Persistent13
可能重复[连接到远程服务器失败使用WinRM从PowerShell](https://stackoverflow.com/questions/16010091/connecting-to-remote-server-failed-using-winrm-from-powershell) – Persistent13