Cmdlets for Neo4j

Build 25.0.9434

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our Neo4j Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Connecting to Neo4j

To connect to Neo4j, you have the following options:

If you are connecting to Neo4j AuraDB, you must use the Query API.

If you are connecting to Self-hosted Neo4j you can choose between the Query API and the HTTP API, depending on your version.

Connecting to Self-hosted Neo4j

Query API

To connect to Neo4j instances via the Query API, set the following connection properties:

  • API: Set this to Query.
  • Server: The server hosting the Neo4j instance. An HTTP or HTTPS protocol prefix may be optionally prepended to the server name or address.
  • Port: The port on which the Neo4j service is running. Self-managed instances have a default port of 7474 for the Query API. If connecting over HTTPS, supply the HTTPS port for the Neo4j instance specified in Server.
  • User: The username of the user using the Neo4j instance.
  • Password: The password of the user using the Neo4j instance.
  • Database: The database to target in the Neo4j instance. Defaults to Neo4j.

HTTP API

To connect to Neo4j instances via the HTTP API, set the following connection properties:

  • API: Set this to HTTP.
  • Server: The server hosting the Neo4j instance. An HTTP or HTTPS protocol prefix may be optionally prepended to the server name or address.
  • Port: The port on which the Neo4j service is running. The provider connects to HTTP 7474 port by default. If connecting over HTTPS, supply the HTTPS port for the Neo4j instance specified in Server.
  • User: The username of the user using the Neo4j instance.
  • Password: The password of the user using the Neo4j instance.
  • Database: The database to target in the Neo4j instance. Defaults to Neo4j.

Connecting to Neo4j AuraDB

Neo4j AuraDB

To connect to Neo4j Aura instances, the required properties will be the same as the Query API configuration above. Notes on finding property values are below.

  • API: Set this to Query.
  • Server: Found in Query API URL in the Inspect menu of the instance in the Neo4j Aura cloud console. Nothing after Neo4j.io should be provided.
  • Port: Set this to 443.
  • User: The username of the user using the Neo4j instance.
  • Password: Provided only once when creating the instance or when a new user is invited.
  • Database: Currently, Neo4j Aura deployments do not allow changing the database name from the default value of Neo4j.

Creating a Connection Object

You can then use the Connect-Neo4j cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-Neo4j -server "localhost" -port "7474" -user "neo4j" -password "password"

Retrieving Data

The Select-Neo4j cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-Neo4j -Connection $conn -Table "ProductCategory" -Columns @("CategoryId, CategoryName") -Where "CategoryOwner='Bob'"
The Invoke-Neo4j cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-Neo4j -Connection $conn -Table ProductCategory -Where "CategoryOwner = 'Bob'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myProductCategoryData.csv -NoTypeInformation

You will notice that we piped the results from Select-Neo4j into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-Neo4j -server "localhost" -port "7474" -user "neo4j" -password "password"
PS C:\> $row = Select-Neo4j -Connection $conn -Table "ProductCategory" -Columns (CategoryId, CategoryName) -Where "CategoryOwner = 'Bob'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "ProductCategory",
  "Columns":  [

  ],
  "CategoryId":  "MyCategoryId",
  "CategoryName":  "MyCategoryName"
} 

Deleting Data

The following line deletes any records that match the criteria:

Select-Neo4j -Connection $conn -Table ProductCategory -Where "CategoryOwner = 'Bob'" | Remove-Neo4j

Modifying Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Neo4j, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyProductCategoryUpdates.csv | %{
  $record = Select-Neo4j -Connection $conn -Table ProductCategory -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-Neo4j -Connection $conn -Table ProductCategory -Columns @("CategoryId","CategoryName") -Values @($_.CategoryId, $_.CategoryName) -Where "Id  = `'$_.Id`'"
  }else{
    Add-Neo4j -Connection $conn -Table ProductCategory -Columns @("CategoryId","CategoryName") -Values @($_.CategoryId, $_.CategoryName)
  }
}

Copyright (c) 2025 CData Software, Inc. - All rights reserved.
Build 25.0.9434