locked
Powershell to connect to 365 online doesn't display errors as expected RRS feed

  • Question

  • Hi all,

    I'm using Microsoft.Xrm.Data.Powershell: PowerShell for Dynamics CRM Organization Data. But I find deliberately entering the wrong URL to test failure to make a connection doesn't get me what I expected. I'm looking for an error that I can catch and act on but no error is thrown.

    It does display a message in the script window "WARNING: No Result". But is not treated as an error and moves onto the next line of the script. So in the end it's impossible to tell is the result has no data because of a failed connection or the record did not exist.

    Is there a different way to check if a valid connection was made to the CRM organisation before moving onto the next step?

    $CRMServerUrl = 'https://incorrecturl.crm6.dynamics.com'
    $Cred = Get-Credential
    
    $global:conn = Connect-CrmOnline -Credential $Cred -ServerUrl $CRMServerUrl
    
    $MonitoringRecordFetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="account">
        <attribute name="name" />
        <attribute name="accountnumber" />
        <filter type="and">
          <condition attribute="name" operator="eq" value="My Account" />
        </filter>
      </entity>
    </fetch>'
    
    $MonitoringRecord = Get-CrmRecordsByFetch -conn $conn -Fetch $MonitoringRecordFetch


    Monday, March 6, 2017 6:47 AM

All replies

  • A little clarification to the above...

    It's at the point of creating the connection where I'd like to see the error:

    $global:conn = Connect-CrmOnline -Credential $Cred -ServerUrl $CRMServerUrl

    Rather I'm getting the "Warning: No Results" at the point of running the fetch. So the warning does not specify if there's a connection issue or the record does not exist.

    Monday, March 6, 2017 10:28 PM