从非管理员上下文执行时,Get-CrmConnection失败(3.3.0.857)

时间:2019-08-20 11:58:15

标签: powershell dynamics-crm dynamics-crm-2011 microsoft-dynamics

我正在尝试执行Get-CrmConnection以从Powershell连接到Dynamics 365,但是从非管理性Powershell上下文执行时,该命令返回以下内容:

Get-CrmConnection -ConnectionString "AuthType=Office365;Username=xxx;Password=xxx;Url=https://xxx.crm.dynamics.com"

Get-CrmConnection : Failed to connect to CRM: Unable to Login to Dynamics CRM
At line:1 char:1
+ Get-CrmConnection -ConnectionString "AuthType=Office365;Username=crm_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (:) [Get-CrmConnection], Exception
    + FullyQualifiedErrorId : -10,Microsoft.Xrm.Tooling.CrmConnector.Powershell.Commands.GetCrmConnectionCommand

我安装了3.3.0.857版本的连接器。

其他信息

如果我在管理员提示的上下文中执行相同的命令,则可以无问题地进行连接。

我需要此命令在Administrator上下文之外运行,因为此脚本将作为Azure DevOps管道的一部分被调用。在Azure DevOps中托管的管道中执行此代码时,会发生相同的问题。

2 个答案:

答案 0 :(得分:2)

我能够找到不涉及升级至Admin的问题的解决方案。

在运行-Verbose时使用Get-CrmConnection选项,我看到发生的错误是主机强行关闭了连接。稍作搜索后,我遇到了this个论坛帖子。上一篇文章提出了尝试将其添加到我的脚本中的建议:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

我尝试过,现在一切正常,无论是否管理员。

答案 1 :(得分:0)

您可以使用以下命令以提升模式运行任何脚本:

$script = "-file C:\crmscript.ps1"
Start-Process powershell -Verb RunAs -ArgumentList $script

您可以使用verbs属性下的System.Diagnostics.ProcessStartInfo对象为任何过程获取有效的动词。在这种情况下,RunAs是有效的动词,用于以提升模式启动powershell进程。

然后可以将其合并到Azure Pipelines / DevOps中。

希望这会有所帮助!

相关问题