Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to CRM 2016 IFD in PowerShell

I would like to connect to CRM 2016 server using PowerShell cmdlet Get-CrmConnection included in the SDK.

I am having trouble finding the correct connection string.

Connecting to the server in in the local network works normally:

Get-CrmConnection -ConnectionString "Url=http://<server>/OrganizationName;"

But connecting to the server configured for IFD fails:

Get-CrmConnection -ConnectionString "Url=https://crm.ourdomain.com/"

Get-CrmConnection : Organization cannot be null or empty.
Parameter name: Organization Name
At line:1 char:1
+ Get-CrmConnection -ConnectionString "Url=https://crm.ourdomain.com/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SyntaxError: (:) [Get-CrmConnection], ArgumentNullException
    + FullyQualifiedErrorId : -9,Microsoft.Xrm.Tooling.CrmConnector.Powershell.Commands.GetCrmConnectionCommand

I tried adding AuthType parameter in the connection string, providing Organization name, but no success. Important thing is that I can connect using the interactive mode:

Get-CrmConnection -InteractiveMode

Interactive mode window

This returns the following connection:

IsReady                        : True
IsBatchOperationsAvailable     : True
Authority                      :
OAuthUserId                    :
ActiveAuthenticationType       : AD
OrganizationServiceProxy       : Microsoft.Xrm.Tooling.Connector.CrmWebSvc+ManagedTokenOrganizationServiceProxy
OrganizationWebProxyClient     :
LastCrmError                   : OrganizationWebProxyClient is null
LastCrmException               :
CrmConnectOrgUriActual         : https://crm.ourdomain.com/XRMServices/2011/Organization.svc
ConnectedOrgFriendlyName       : OrganizationName
ConnectedOrgUniqueName         : OrganizationName
ConnectedOrgPublishedEndpoints : {[WebApplication, https://crm.ourdomain.com/], [OrganizationService,
                             https://crm.ourdomain.com/XRMServices/2011/Organization.svc],
                             [OrganizationDataService,
                             https://crm.ourdomain.com/XRMServices/2011/OrganizationData.svc]}
ConnectionLockObject           : System.Object
ConnectedOrgVersion            : 8.0.1.79
like image 760
Dejan Dular Avatar asked Feb 06 '23 13:02

Dejan Dular


1 Answers

There are some big gotchas with the microsoft.xrm.tooling.connector CrmConnection that can have you banging your head against the wall.

To quote from http://crmtipoftheday.com/2016/01/14/rumors-about-microsoft-xrm-client-death-are-exaggerated/

Note the following:

  • Url must be in the form of https://orgname.contoso.com/orgname. For on-premises and IFD deployments the connector expects orgname to be
    at the end and looks like it does not make any attempt to deduce
    orgname from the server url.
  • Domain name must be specified but it’s not passed via claims, so it can be anything. Really any non-empty string o__O
  • Username must be UPN. If it’s not, then, since domain name is not passed it, ADFS 3.0 throws a fit (ADFS 2.0 assumes the domain)

The following works for me

get-crmconnection -ConnectionString "Server=https://{orgname}.{domain}.com/{orgname}; Domain=this_isnt_used_but_must_be_provided; UserName={domain}\{user}; Password={password}"

so does the slightly modified username as UPN

get-crmconnection -ConnectionString "Server=https://{orgname}.{domain}.com/{orgname}; Domain=this_isnt_used_but_must_be_provided; UserName={user}@{domain}; Password={password}"
like image 109
Zeph Avatar answered Feb 15 '23 09:02

Zeph