Automate Teradata Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Teradata ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Teradata databases.



Are you looking for a quick and easy way to access Teradata data from PowerShell? We show how to use the Cmdlets for Teradata and the CData ADO.NET Provider for Teradata to connect to Teradata data and synchronize, automate, download, and more.

The CData Cmdlets for Teradata 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 Teradata.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Teradata API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Teradata data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Teradata. To access Teradata data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Teradata.

After obtaining the needed connection properties, accessing Teradata data in PowerShell consists of three basic steps.

To connect to Teradata, provide authentication information and specify the database server name.

  • User: Set this to the username of a Teradata user.
  • Password: Set this to the password of the Teradata user.
  • DataSource: Specify the Teradata server name, DBC Name, or TDPID.
  • Port: Specify the port the server is running on.
  • Database: Specify the database name. If not specified, the default database is used.

PowerShell

  1. Install the module:

    Install-Module TeradataCmdlets
  2. Connect:

    $teradata = Connect-Teradata -User "$User" -Password "$Password" -Server "$Server" -Database "$Database"
  3. Search for and retrieve data:

    $categoryid = "5" $northwindproducts = Select-Teradata -Connection $teradata -Table "NorthwindProducts" -Where "CategoryId = `'$CategoryId`'" $northwindproducts

    You can also use the Invoke-Teradata cmdlet to execute SQL commands:

    $northwindproducts = Invoke-Teradata -Connection $teradata -Query 'SELECT * FROM NorthwindProducts WHERE CategoryId = @CategoryId' -Params @{'@CategoryId'='5'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Teradata\lib\System.Data.CData.Teradata.dll")
  2. Connect to Teradata:

    $conn= New-Object System.Data.CData.Teradata.TeradataConnection("User=myuser;Password=mypassword;Server=localhost;Database=mydatabase;") $conn.Open()
  3. Instantiate the TeradataDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT ProductId, ProductName from NorthwindProducts" $da= New-Object System.Data.CData.Teradata.TeradataDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.productid $_.productname }

Update Teradata Data

PowerShell

Update-Teradata -Connection $Teradata -Columns @('ProductId','ProductName') -Values @('MyProductId', 'MyProductName') -Table NorthwindProducts -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Teradata.TeradataCommand("UPDATE NorthwindProducts SET CategoryId='5' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Teradata.TeradataParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Teradata Data

PowerShell

Add-Teradata -Connection $Teradata -Table NorthwindProducts -Columns @("ProductId", "ProductName") -Values @("MyProductId", "MyProductName")

ADO.NET

$cmd = New-Object System.Data.CData.Teradata.TeradataCommand("INSERT INTO NorthwindProducts (CategoryId) VALUES (@myCategoryId)", $conn) $cmd.Parameters.Add(new System.Data.CData.Teradata.TeradataParameter("@myCategoryId","5")) $cmd.ExecuteNonQuery()

Delete Teradata Data

PowerShell

Remove-Teradata -Connection $Teradata -Table "NorthwindProducts" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Teradata.TeradataCommand("DELETE FROM NorthwindProducts WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Teradata.TeradataParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()