Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Automate IBM Informix Integration Tasks from PowerShell
Are you in search of a quick and easy way to access IBM Informix data from PowerShell? This article demonstrates how to utilize the IBM Informix Cmdlets for tasks like connecting to IBM Informix data, automating operations, downloading data, 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.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to IBM Informix, 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.
Once you have acquired the necessary connection properties, accessing IBM Informix data in PowerShell can be enabled in three 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
-
Install the module:
Install-Module InformixCmdlets
-
Connect:
$informix = Connect-Informix -Server "$Server" -Port "$Port" -User "$User" -Password "$Password" -Database "$Database"
-
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
-
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")
-
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()
-
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-Object 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-Object 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-Object System.Data.CData.Informix.InformixParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject