Automate IBM Informix Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

IBM Informix ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with IBM Informix.



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

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

Cmdlets or ADO.NET?

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

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

Set the following properties to connect to IBM Informix

  • Server: Set this to the name of the server running IBM Informix.
  • Port: Set this to the port the IBM Informix server is listening on.
  • Database: Set this to the name of the IBM Informix database.
  • User: Set this to the username of a user allowed to access the database.
  • Password: Set this to the password of a user allowed to access the database.

PowerShell

  1. Install the module:

    Install-Module InformixCmdlets
  2. Connect:

    $informix = Connect-Informix -Server "$Server" -Port "$Port" -User "$User" -Password "$Password" -Database "$Database"
  3. Search for and retrieve data:

    $category = "US" $books = Select-Informix -Connection $informix -Table "Books" -Where "Category = `'$Category`'" $books

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

    $books = Invoke-Informix -Connection $informix -Query 'SELECT * FROM Books WHERE Category = @Category' -Params @{'@Category'='US'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.Informix.InformixConnection("Server=10.0.1.2;Port=50000;User=admin;Password=admin;Database=test;") $conn.Open()
  3. Instantiate the InformixDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, Price from Books" $da= New-Object System.Data.CData.Informix.InformixDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.price }

Update IBM Informix Data

PowerShell

Update-Informix -Connection $Informix -Columns @('Id','Price') -Values @('MyId', 'MyPrice') -Table Books -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Informix.InformixCommand("UPDATE Books SET Category='US' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Informix.InformixParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert IBM Informix Data

PowerShell

Add-Informix -Connection $Informix -Table Books -Columns @("Id", "Price") -Values @("MyId", "MyPrice")

ADO.NET

$cmd = New-Object System.Data.CData.Informix.InformixCommand("INSERT INTO Books (Category) VALUES (@myCategory)", $conn) $cmd.Parameters.Add(new System.Data.CData.Informix.InformixParameter("@myCategory","US")) $cmd.ExecuteNonQuery()

Delete IBM Informix Data

PowerShell

Remove-Informix -Connection $Informix -Table "Books" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Informix.InformixCommand("DELETE FROM Books WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.Informix.InformixParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()