Ready to get started?

Download a free trial of the FHIR Cmdlets to get started:

 Download Now

Learn more:

FHIR Icon FHIR Data Cmdlets

An easy-to-use set of PowerShell Cmdlets offering real-time access to FHIR. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.

PowerShell Scripting to Replicate FHIR Data to MySQL

Write a simple PowerShell script to replicate FHIR data to a MySQL database.

The CData Cmdlets for FHIR offer live access to FHIR data from within PowerShell. Using PowerShell scripts, you can easily automate regular tasks like data replication. This article will walk through using the CData Cmdlets for FHIR and the CData Cmdlets for MySQL in PowerShell to replicate FHIR data to a MySQL database.

After obtaining the needed connection properties, accessing FHIR data in PowerShell and preparing for replication consists of four basic steps.

Set URL to the Service Base URL of the FHIR server. This is the address where the resources are defined in the FHIR server you would like to connect to. Set ConnectionType to a supported connection type. Set ContentType to the format of your documents. Set AuthScheme based on the authentication requirements for your FHIR server.

Generic, Azure-based, AWS-based, and Google-based FHIR server implementations are supported.

Sample Service Base URLs

  • Generic: http://my_fhir_server/r4b/
  • Azure:
  • AWS:
  • Google:

Generic FHIR Instances

The product supports connections to custom instances of FHIR. Authentication to custom FHIR servers is handled via OAuth (read more about OAuth in the Help documentation. Before you can connect to custom FHIR instances, you must set ConnectionType to Generic.

Collecting FHIR Data

  1. Install the module:

    Install-Module FHIRCmdlets
  2. Connect to FHIR:

    $fhir = Connect-FHIR -URL $URL -ConnectionType $ConnectionType -ContentType $ContentType -AuthScheme $AuthScheme
  3. Retrieve the data from a specific resource:

    $data = Select-FHIR -Connection $fhir -Table "Patient"

    You can also use the Invoke-FHIR cmdlet to execute pure SQL-92 statements:

    $data = Invoke-FHIR -Connection $fhir -Query 'SELECT * FROM Patient WHERE [address-city] = @[address-city]' -Params @{'@[address-city]'='New York'}
  4. Save a list of the column names from the returned data.

    $columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name

Inserting FHIR Data into the MySQL Database

With the data and column names collected, you are ready to replicate the data into a MySQL database.

  1. Install the module:

    Install-Module MySQLCmdlets
  2. Connect to MySQL, using the server address and port of the MySQL server, valid user credentials, and a specific database with the table in which the data will be replicated:

    $mysql = Connect-MySQL -User $User -Password $Password -Database $Database -Server $Server -Port $Port
  3. Loop through the FHIR data, store the values, and use the Add-MySQL cmdlet to insert the data into the MySQL database, one row at a time. In this example, the table will need to have the same name as the FHIR resource (Patient) and to exist in the database.

    $data | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "Patient" -Columns $columns -Values $values }

You have now replicated your FHIR data to a MySQL database. This gives you freedom to work with FHIR data in the same way that you work with other MySQL tables, whether that is performing analytics, building reports, or other business functions.


  • Once you have connected to FHIR and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:

    Select-FHIR -Connection $fhir -Table "Patient" | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "Patient" -Columns $columns -Values $values }
  • If you wish to replicate the FHIR data to another database using another PowerShell module, you will want to exclude the Columns, Connection, and Table columns from the data returned by the Select-FHIR cmdlet since those columns are used to help pipe data from one CData cmdlet to another:

    $columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name | ? {$_ -NotIn @('Columns','Connection','Table')}