Cmdlets for Greenhouse

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

Connecting to Greenhouse

You need an API key to connect to Greenhouse. To create an API key, follow the steps below:

  1. Click the Configure icon in the navigation bar and locate Dev Center on the left.
  2. Select API Credential Management.
  3. Click Create New API Key.
    • Set "API Type" to Harvest.
    • Set "Partner" to custom.
    • Optionally, provide a description.
  4. Proceed to Manage permissions and select the appropriate permissions based on the resources you want to access through the cmdlet.
  5. Copy the created key and set APIKey to that value.

Creating a Connection Object

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

$conn = Connect-Greenhouse -APIKey 'YourAPIKey'

Retrieving Data

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

$results = Select-Greenhouse -Connection $conn -Table "Applications" -Columns @("Id, CandidateId") -Where "Id='27838971007'"
The Invoke-Greenhouse 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-Greenhouse -Connection $conn -Table Applications -Where "Id = '27838971007'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myApplicationsData.csv -NoTypeInformation

You will notice that we piped the results from Select-Greenhouse 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-Greenhouse -APIKey 'YourAPIKey'
PS C:\> $row = Select-Greenhouse -Connection $conn -Table "Applications" -Columns (Id, CandidateId) -Where "Id = '27838971007'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "Applications",
  "Columns":  [

  ],
  "Id":  "MyId",
  "CandidateId":  "MyCandidateId"
} 

Modifying Data

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

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

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