Cmdlets for Alfresco

Build 21.0.7930

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 Alfresco Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module AlfrescoCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module AlfrescoCmdlets;

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

$conn = Connect-Alfresco -User "CData" -Password "CData" -InstanceURL "https://api-explorer.alfresco.com"

Authenticating to Alfresco

To connect to Alfresco, the following connection properties must be supplied: User, Password, and InstanceURL. User and Password should correspond to the login credentials that you use to access Alfresco in a web browser. InstanceURL corresponds to the Alfresco instance you will be querying. For instance, if you expect your queries to hit https://search-demo.dev.alfresco.me/alfresco/api/-default-/public/search/versions/1/sql, you should supply search-demo.dev.alfresco.me for InstanceURL.

Retrieving Data

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

$results = Select-Alfresco -Connection $conn -Table "Alfresco" -Columns @("DBID, Column1") -Where "Column2='Bob'"
The Invoke-Alfresco 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-Alfresco -Connection $conn -Table Alfresco -Where "Column2 = 'Bob'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myAlfrescoData.csv -NoTypeInformation

You will notice that we piped the results from Select-Alfresco 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-Alfresco -User "CData" -Password "CData" -InstanceURL "https://api-explorer.alfresco.com"
PS C:\> $row = Select-Alfresco -Connection $conn -Table "Alfresco" -Columns (DBID, Column1) -Where "Column2 = 'Bob'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "Alfresco",
  "Columns":  [

  ],
  "DBID":  "MyDBID",
  "Column1":  "MyColumn1"
} 

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930