Azure-runbook中的New-PSSession:访问被拒绝(ARM) [英] New-PSSession in an Azure-runbook: Access denied (ARM)

查看:312
本文介绍了Azure-runbook中的New-PSSession:访问被拒绝(ARM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用中提供的建议,我能够在Azure VM(1)上设置winrm.

With the advice provided in this answer I was able to set up the winrm on a Azure VM(1).

现在,我可以使用

  • 任何Azure VM(2)到Azure VM(1)
  • 将我的本地计算机连接到Azure VM(1)

但是,如果我在Azure Runbook中执行完全相同的操作,

But if I do exactly the same within an Azure runbook,

$cred = Get-AutomationPSCredential -Name "admin"
InlineScript
{
   $vmSession = New-PSSession -ConnectionUri 'https://xxx.yyy.cloudapp.azure.com:5986' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
}

它失败并显示错误消息:

it fails with the error message:

New-PSSession:[xxx.yyy.cloudapp.azure.com]连接到远程服务器 xxx.yyy.cloudapp.azure.com失败,并显示以下错误消息:访问被拒绝.

New-PSSession : [xxx.yyy.cloudapp.azure.com] Connecting to remote server xxx.yyy.cloudapp.azure.com failed with the following error message : Access is denied.

作为用户,我使用`localhost \ admin,并且我是positiv,密码正确(仔细检查了密码).

As user I use `localhost\admin" and I'm positiv, the password is correct (double-checked it).

Q 如何克服拒绝访问?

更新

PS工作流程让我受益匪浅.因此,以上代码中仅存在一个较小的语法问题.如果有人分享正确的答案,我很乐意投票并接受.

PS-workflow got the best of me. So, there is only a minor syntactical problem in the code above. If somebody shares the right answer I'm happy to up-vote and accept it.

推荐答案

根据此

默认情况下,工作流中定义的变量不是 对InlineScript脚本块中的命令可见.使 InlineScript可见的工作流变量,请使用$ Using范围 修饰符.每个范围仅需要一次使用$ Using范围修饰符 InlineScript中的变量.

By default, the variables that are defined in a workflow are not visible to the commands in the InlineScript script block. To make workflow variables visible to the InlineScript, use the $Using scope modifier. The $Using scope modifier is required only once for each variable in the InlineScript.

因此,您需要按如下所示修改脚本:

So, you need modify your script as below:

$cred = Get-AutomationPSCredential -Name "admin"
InlineScript
{
   $vmSession = New-PSSession -ConnectionUri 'https://xxx.yyy.cloudapp.azure.com:5986' -Credential $Using:cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
}

这篇关于Azure-runbook中的New-PSSession:访问被拒绝(ARM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆