web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Export Contacts with PowerShell

(0) ShareShare
ReportReport
Posted on by

Hello, I have a customer with Dynamics CRM Online and they asked me if it is possible to export all contacts they have stored in Dynamics CRM Online as a .csv (or equal) to a network drive. At the end they want a scheduled job that do this once per day. They want to export this data to a third party system. Do you know if this is possible? Has someone may already done something like that. Actually I was able to connect to their CRM  Instance (with PowerShell) but there is no Get-Contacts... I am glad for any solutions, thank you!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I don't think this is possible. I would suggest to use SSIS or develop .NET application.

  • Community Member Profile Picture
    on at

    Hello Andrii

    Cool, thank you for the quick reply! I will have a look at SSIS.

  • Suggested answer
    tpeschat Profile Picture
    4,930 on at

    Hi,

    maybe this can be achieved with the following powershell module:

    blogs.msdn.com/.../powershell-module-for-performing-data-operations-and-manipulating-user-and-system-settings-in-crm.aspx

    Hth Thomas

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Looks great, Thomas! Thanks for sharing!

  • tpeschat Profile Picture
    4,930 on at

    Pleasure ;)

  • Community Member Profile Picture
    on at

    Hi Thomas, you gave us the correct hint, thank you! My colleague will post the solution.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hello Thomas

    Thank you for help. With the module form Kenichiro Nakamura and Sean McNellis it was easy to create the Powershell script below. 

    Import-Module Microsoft.Xrm.Data.Powershell
    $Cred = import-clixml -path $credpath
    $conn = Get-CrmConnection -InteractiveMode
    
    $result = Get-CrmRecordsByFetch @"
        <fetch mapping="logical" version="1.0">
      <entity name="account">
        <attribute name="customertypecode" alias="customertypecode" />
        <attribute name="name" alias="company_name" />
        <attribute name="telephone1" alias="company_telephone1" />
        <attribute name="telephone2" alias="company_telephone2" />
        <attribute name="fax" alias="company_fax" />
        <attribute name="websiteurl" alias="company_url" />
        <attribute name="emailaddress1" alias="company_emailaddress1" />
        <attribute name="address1_line1" alias="company_address1_line1" />
        <attribute name="address1_line2" alias="company_address1_line2" />
        <attribute name="address1_line3" alias="company_address1_line3" />
        <attribute name="address1_postalcode" alias="company_address1_postalcode" />
        <attribute name="address1_city" alias="company_address1_city" />
        <attribute name="address1_country" alias="company_address1_country" />
        <link-entity name="contact" from="accountid" to="accountid" link-type="inner">
          <attribute name="lastname" alias="lastname" />
          <attribute name="firstname" alias="firstname" />
          <attribute name="salutation" alias="salutation" />
          <attribute name="jobtitle" alias="jobtitle" />
          <attribute name="telephone1" alias="telephone1" />
          <attribute name="telephone2" alias="telephone2" />
          <attribute name="mobilephone" alias="mobilephone" />
          <attribute name="fax" alias="fax" />
          <attribute name="emailaddress1" alias="emailaddress1" />
          <attribute name="emailaddress2" alias="emailaddress2" />
          <attribute name="address1_name" alias="address1_name" />
          <attribute name="address1_line1" alias="address1_line1" />
          <attribute name="address1_line2" alias="address1_line2" />
          <attribute name="address1_line3" alias="address1_line3" />
          <attribute name="address1_postalcode" alias="address1_postalcode" />
          <attribute name="address1_city" alias="address1_city" />
          <attribute name="address1_country" alias="address1_country" />
          <attribute name="address2_name" alias="address2_name" />
          <attribute name="address2_line1" alias="address2_line1" />
          <attribute name="address2_line2" alias="address2_line2" />
          <attribute name="address2_line3" alias="address2_line3" />
          <attribute name="address2_postalcode" alias="address2_postalcode" />
          <attribute name="address2_city" alias="address2_city" />
          <attribute name="address2_country" alias="address2_country" />
        </link-entity>
      </entity>
    </fetch>
    "@
    
    $result.CrmRecords | Select -Property lastname, firstname, salutation, jobtitle, telephone1, telephone2, mobilephone,fax,emailaddress1,emailaddress2,address1_name,address1_line1,address1_line2,address1_line3,address1_postalcode, address1_city,address1_country, address2_name,address2_line1,address2_line2,address2_line3,address2_postalcode ,address2_city,address2_country, customertypecode,company_name,company_telephone1,company_telephone2,company_fax,company_url,company_emailaddress1, company_address1_line1,company_address1_line2,company_address1_line3, company_address1_postalcode,company_address1_city,company_address1_country | Export-Csv -Encoding UTF8 -Path C:\export.csv -Delimiter ";"

    To create the FetchXML I used the website http://www.sql2fetchxml.com/. The user need read rights on the data (for CRM Online the user need a license).  

  • tpeschat Profile Picture
    4,930 on at

    Nice, thx for sharing

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans