Ready to get started?

Download a free trial of the EnterpriseDB Data Provider to get started:

 Download Now

Learn more:

EnterpriseDB Icon EnterpriseDB ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with EnterpriseDB.

Automate EnterpriseDB Integration Tasks from PowerShell



Are you in search of a quick and easy way to access EnterpriseDB data from PowerShell? This article demonstrates how to utilize the EnterpriseDB Cmdlets for tasks like connecting to EnterpriseDB data, automating operations, downloading data, and more.

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

PowerShell Cmdlets or ADO.NET Provider?

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

Once you have acquired the necessary connection properties, accessing EnterpriseDB data in PowerShell can be enabled in three steps.

The following connection properties are required in order to connect to data.

  • Server: The host name or IP of the server hosting the EnterpriseDB database.
  • Port: The port of the server hosting the EnterpriseDB database.

You can also optionally set the following:

  • Database: The default database to connect to when connecting to the EnterpriseDB Server. If this is not set, the user's default database will be used.

Connect Using Standard Authentication

To authenticate using standard authentication, set the following:

  • User: The user which will be used to authenticate with the EnterpriseDB server.
  • Password: The password which will be used to authenticate with the EnterpriseDB server.

Connect Using SSL Authentication

You can leverage SSL authentication to connect to EnterpriseDB data via a secure session. Configure the following connection properties to connect to data:

  • SSLClientCert: Set this to the name of the certificate store for the client certificate. Used in the case of 2-way SSL, where truststore and keystore are kept on both the client and server machines.
  • SSLClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
  • SSLClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
  • SSLClientCertType: The certificate type of the client store.
  • SSLServerCert: The certificate to be accepted from the server.

PowerShell

  1. Install the module:

    Install-Module EnterpriseDBCmdlets
  2. Connect:

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

    $shipcountry = "USA" $orders = Select-EnterpriseDB -Connection $enterprisedb -Table "Orders" -Where "ShipCountry = `'$ShipCountry`'" $orders

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

    $orders = Invoke-EnterpriseDB -Connection $enterprisedb -Query 'SELECT * FROM Orders WHERE ShipCountry = @ShipCountry' -Params @{'@ShipCountry'='USA'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.EnterpriseDB.EnterpriseDBConnection("User=postgres;Password=admin;Database=postgres;Server=127.0.0.1;Port=5444") $conn.Open()
  3. Instantiate the EnterpriseDBDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT ShipName, ShipCity from Orders" $da= New-Object System.Data.CData.EnterpriseDB.EnterpriseDBDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.shipname $_.shipcity }

Update EnterpriseDB Data

PowerShell

Update-EnterpriseDB -Connection $EnterpriseDB -Columns @('ShipName','ShipCity') -Values @('MyShipName', 'MyShipCity') -Table Orders -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.EnterpriseDB.EnterpriseDBCommand("UPDATE Orders SET ShipCountry='USA' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.EnterpriseDB.EnterpriseDBParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert EnterpriseDB Data

PowerShell

Add-EnterpriseDB -Connection $EnterpriseDB -Table Orders -Columns @("ShipName", "ShipCity") -Values @("MyShipName", "MyShipCity")

ADO.NET

$cmd = New-Object System.Data.CData.EnterpriseDB.EnterpriseDBCommand("INSERT INTO Orders (ShipCountry) VALUES (@myShipCountry)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.EnterpriseDB.EnterpriseDBParameter("@myShipCountry","USA"))) $cmd.ExecuteNonQuery()

Delete EnterpriseDB Data

PowerShell

Remove-EnterpriseDB -Connection $EnterpriseDB -Table "Orders" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.EnterpriseDB.EnterpriseDBCommand("DELETE FROM Orders WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.EnterpriseDB.EnterpriseDBParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()