![]() |
VOOZH | about |
The CData Cmdlets for Airtable are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Airtable.
The Cmdlets are not only a PowerShell interface to Airtable, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Airtable data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Airtable. To access Airtable data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Airtable.
Once you have acquired the necessary connection properties, accessing Airtable data in PowerShell can be enabled in three steps.
APIKey, BaseId and TableNames parameters are required to connect to Airtable. ViewNames is an optional parameter where views of the tables may be specified.
Install the module:
Install-Module AirtableCmdlets
Connect:
$airtable = Connect-Airtable -APIKey "$APIKey" -BaseId "$BaseId" -TableNames "$TableNames" -ViewNames "$ViewNames"
Search for and retrieve data:
$column2 = "SomeValue" $sampletable_1 = Select-Airtable -Connection $airtable -Table "SampleTable_1" -Where "Column2 = `'$Column2`'" $sampletable_1
You can also use the Invoke-Airtable cmdlet to execute SQL commands:
$sampletable_1 = Invoke-Airtable -Connection $airtable -Query 'SELECT * FROM SampleTable_1 WHERE Column2 = @Column2' -Params @{'@Column2'='SomeValue'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Airtable\lib\System.Data.CData.Airtable.dll")
Connect to Airtable:
$conn= New-Object System.Data.CData.Airtable.AirtableConnection("APIKey=keymz3adb53RqsU;BaseId=appxxN2fe34r3rjdG7;TableNames=Table1,...;ViewNames=Table1.View1,...;")
$conn.Open()
Instantiate the AirtableDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Column1 from SampleTable_1"
$da= New-Object System.Data.CData.Airtable.AirtableDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.column1
}
Update-Airtable -Connection $Airtable -Columns @('Id','Column1') -Values @('MyId', 'MyColumn1') -Table SampleTable_1 -Id "MyId"
$cmd = New-Object System.Data.CData.Airtable.AirtableCommand("UPDATE SampleTable_1 SET Column2='SomeValue' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Airtable.AirtableParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Airtable -Connection $Airtable -Table SampleTable_1 -Columns @("Id", "Column1") -Values @("MyId", "MyColumn1")
$cmd = New-Object System.Data.CData.Airtable.AirtableCommand("INSERT INTO SampleTable_1 (Column2) VALUES (@myColumn2)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Airtable.AirtableParameter("@myColumn2","SomeValue")))
$cmd.ExecuteNonQuery()
Remove-Airtable -Connection $Airtable -Table "SampleTable_1" -Id "MyId"
$cmd = New-Object System.Data.CData.Airtable.AirtableCommand("DELETE FROM SampleTable_1 WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Airtable.AirtableParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Airtable Data Provider to get started:
Download NowLearn more:
👁 Airtable IconRapidly create and deploy powerful .NET applications that integrate with Airtable.