Ready to get started?

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

 Download Now

Learn more:

Snowflake Enterprise Data Warehouse Icon Snowflake ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Snowflake data warehouse.

Automate Snowflake Integration Tasks from PowerShell



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

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

PowerShell Cmdlets or ADO.NET Provider?

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

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

To connect to Snowflake:

  1. Set User and Password to your Snowflake credentials and set the AuthScheme property to PASSWORD or OKTA.
  2. Set URL to the URL of the Snowflake instance (i.e.: https://myaccount.snowflakecomputing.com).
  3. Set Warehouse to the Snowflake warehouse.
  4. (Optional) Set Account to your Snowflake account if your URL does not conform to the format above.
  5. (Optional) Set Database and Schema to restrict the tables and views exposed.

See the Getting Started guide in the CData driver documentation for more information.

PowerShell

  1. Install the module:

    Install-Module SnowflakeCmdlets
  2. Connect:

    $snowflake = Connect-Snowflake -User "$User" -Password "$Password" -Server "$Server" -Database "$Database" -Warehouse "$Warehouse" -Account "$Account"
  3. Search for and retrieve data:

    $id = "1" $products = Select-Snowflake -Connection $snowflake -Table "Products" -Where "Id = `'$Id`'" $products

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

    $products = Invoke-Snowflake -Connection $snowflake -Query 'SELECT * FROM Products WHERE Id = @Id' -Params @{'@Id'='1'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.Snowflake.SnowflakeConnection("User=Admin;Password=test123;Server=localhost;Database=Northwind;Warehouse=TestWarehouse;Account=Tester1;") $conn.Open()
  3. Instantiate the SnowflakeDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, ProductName from Products" $da= New-Object System.Data.CData.Snowflake.SnowflakeDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.productname }

Update Snowflake Data

PowerShell

Update-Snowflake -Connection $Snowflake -Columns @('Id','ProductName') -Values @('MyId', 'MyProductName') -Table Products -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Snowflake.SnowflakeCommand("UPDATE Products SET Id='1' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Snowflake.SnowflakeParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert Snowflake Data

PowerShell

Add-Snowflake -Connection $Snowflake -Table Products -Columns @("Id", "ProductName") -Values @("MyId", "MyProductName")

ADO.NET

$cmd = New-Object System.Data.CData.Snowflake.SnowflakeCommand("INSERT INTO Products (Id) VALUES (@myId)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Snowflake.SnowflakeParameter("@myId","1"))) $cmd.ExecuteNonQuery()

Delete Snowflake Data

PowerShell

Remove-Snowflake -Connection $Snowflake -Table "Products" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Snowflake.SnowflakeCommand("DELETE FROM Products WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Snowflake.SnowflakeParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()