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 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.
About Snowflake Data Integration
CData simplifies access and integration of live Snowflake data. Our customers leverage CData connectivity to:
- Reads and write Snowflake data quickly and efficiently.
- Dynamically obtain metadata for the specified Warehouse, Database, and Schema.
- Authenticate in a variety of ways, including OAuth, OKTA, Azure AD, Azure Managed Service Identity, PingFederate, private key, and more.
Many CData users use CData solutions to access Snowflake from their preferred tools and applications, and replicate data from their disparate systems into Snowflake for comprehensive warehousing and analytics.
For more information on integrating Snowflake with CData solutions, refer to our blog: https://www.cdata.com/blog/snowflake-integrations.
Getting Started
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:
- Set User and Password to your Snowflake credentials and set the AuthScheme property to PASSWORD or OKTA.
- Set URL to the URL of the Snowflake instance (i.e.: https://myaccount.snowflakecomputing.com).
- Set Warehouse to the Snowflake warehouse.
- (Optional) Set Account to your Snowflake account if your URL does not conform to the format above.
- (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
-
Install the module:
Install-Module SnowflakeCmdlets
-
Connect:
$snowflake = Connect-Snowflake -User "$User" -Password "$Password" -Server "$Server" -Database "$Database" -Warehouse "$Warehouse" -Account "$Account"
-
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
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Snowflake\lib\System.Data.CData.Snowflake.dll")
-
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()
-
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()
CodeProject