【问题标题】:WinRM on Azure RM VMAzure RM VM 上的 WinRM
【发布时间】:2017-01-10 18:31:59
【问题描述】:

我正在尝试连接到 AzureRM 虚拟机。我已经阅读了很多关于 WinRM 的教程,但我仍然无法让它工作:

    Enter-PSSession -ComputerName "$($HOST).cloudapp.net" -Credential $username

当我运行它时,我收到以下错误:

用户名或密码不正确。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题

当我添加 -UseSSL 参数时,我收到此错误:

WinRM 客户端无法处理请求,因为无法解析服务器名称。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。

我输入的凭据是正确的。所以我也尝试了“localhost\$username”,我得到了一个不同的错误:

使用 Kerberos 身份验证时出现以下错误,错误代码为 0x80090311:

所以我尝试使用 -Authentication basic 得到:

WinRM 客户端无法处理该请求。当前在客户端配置中禁用了未加密的流量

但我已经检查并启用了未加密的流量。

以前有人遇到过这个问题吗?关于接下来要尝试什么的任何建议?

    credentials = Get-Credential -UserName $username -Message "Enter Azure account credentials"
    $continue=$false
    Do{
$session = New-PSSession -ComputerName "$($VMName).cloudapp.net" -Credential $credentials 
if ($session -ne $null)
{
  $continue=$true
}
Write-Output "Unable to create a PowerShell session . . . sleeping and trying again in 30 seconds."
Start-Sleep -Seconds 30
      }
   Until(
$continue=$true)

编辑添加现在服务器上的设置:

   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Client

Type            Name                           SourceOfValue   Value
----            ----                           -------------   -----
System.String   NetworkDelayms                                 5000
System.String   URLPrefix                                      wsman
System.String   AllowUnencrypted                               true
Container       Auth
Container       DefaultPorts
System.String   TrustedHosts

还有客户:

   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Client

 Type            Name                           SourceOfValue   Value
 ----            ----                           -------------   -----
 System.String   NetworkDelayms                                 5000
 System.String   URLPrefix                                      wsman
 System.String   AllowUnencrypted                               true
 Container       Auth
 Container       DefaultPorts
 System.String   TrustedHosts                                   @{Value = "XX.XX.XX.XX"}

【问题讨论】:

  • 好吧,用户名或密码不正确...您期望什么...
  • 我已经尝试了大约 20 次,我向你保证......我输入的用户名和密码与我在 Azure 中设置 VM 时使用的用户名和密码相同
  • 我玩得更多了,我输入了一些任意主机名,以查看是否有不同的错误消息(如找不到主机),当我使用第一个命令时,我仍然收到错误用户名和密码。
  • 您确定您正在为 -Credentials 使用凭证对象吗?试试 -Credential (Get-Credential -UserName $Username)
  • 是的,我正在使用该对象...我已经用我正在运行的内容更新了 OP。

标签: powershell azure winrm


【解决方案1】:

也许您可以尝试使用以下 cmdlet。我在我的实验室测试。它对我有用。

$SecureString = Read-Host -AsSecureString 'Enter your password ' | ConvertFrom-SecureString | ConvertTo-SecureString $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "yourusername",$SecureString Enter-PSSession -ComputerName "yourcomputername" -Credential $MySecureCreds

我找到了一个和你类似的question,也许你可以查一下。

更新:

WinRM服务器上,请尝试执行以下cmdlet。

winrm quickconfig

您将收到以下消息。

WinRM 服务已经在这台机器上运行。 WinRM 已设置 在这台计算机上进行远程管理。

客户端电脑上,请尝试使用管理员帐户执行以下 cmdlet。

winrm set winrm/config/client '@{TrustedHosts = "server IP"}'

【讨论】:

  • 我试过这个,我得到了关于用户名和密码的完全相同的错误信息。我尝试将 mylocalmachine\ 添加到用户名,但出现未加密的流量错误。所以基本上我得到了完全相同的错误......另外,你为什么要从安全字符串转换只是为了将它转换为转换为安全字符串?
  • @Jewtus 我已经更新了我的答案,也许你可以尝试在你的服务和客户端上配置WinRM
  • 我已经在机器上完成了这项工作,但我现在已经包含了设置。我确实读过,如果您尝试在没有 AD 的机器上使用 WinRM,您需要设置和配置 SSL 证书。这可能是问题还是这是防火墙配置问题?我再次尝试针对 Azure RM 主机执行此操作。
  • 我能够让它在公共网络上运行,但不能在专用网络上运行……这显然是一个路由器/网络问题。感谢您的帮助沃尔特
  • 你可以使用Microsoft Network Monitor来抓包。你可以从link下载它
【解决方案2】:

以下参数有助于通过 WINRM 连接 Azure VM

    $hostName="DomainName" 
$winrmPort = "5986"
# Get the credentials of the machine
$cred = Get-Credential
# Connect to the machine
$soptions = New-PSSessionOption -SkipCACheck
Enter-PSSession -ComputerName $hostName -Port $winrmPort -Credential $cred -SessionOption $soptions -UseSSL

【讨论】:

  • 连接 WIRM 的脚本:$hostName="DomainName" $winrmPort = "5986" $username = "UserName" $secpasswd = ConvertTo-SecureString “Password” -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential (“$username”, $secpasswd) $soptions = New-PSSessionOption -SkipCACheck Enter-PSSession -ComputerName $hostName -Port $winrmPort -Credential $mycreds -SessionOption $soptions -UseSSL
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-10
  • 1970-01-01
  • 2021-12-23
  • 2021-03-01
  • 1970-01-01
  • 2017-05-18
  • 1970-01-01
相关资源
最近更新 更多