![]() |
VOOZH | about |
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.
CData simplifies access and integration of live Snowflake data. Our customers leverage CData connectivity to:
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.
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:
See the Getting Started guide in the CData driver documentation for more information.
Install the module:
Install-Module SnowflakeCmdlets
Connect:
$snowflake = Connect-Snowflake -Authscheme "$Authscheme" -URL "$URL" -User "$User" -Password "$Password" -Server "$Server" -Database "$Database" -Warehouse "$Warehouse" -Account "$Account" -MFACode "$MFACode"
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'}
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("Authscheme=Password;URL=https://myaccount.snowflakecomputing.com;User=Admin;Password=test123;Server=localhost;Database=Northwind;Warehouse=TestWarehouse;Account=Tester1;MFACode=YourMFACode")
$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 -Connection $Snowflake -Columns @('Id','ProductName') -Values @('MyId', 'MyProductName') -Table Products -Id "MyId"
$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()
Add-Snowflake -Connection $Snowflake -Table Products -Columns @("Id", "ProductName") -Values @("MyId", "MyProductName")
$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()
Remove-Snowflake -Connection $Snowflake -Table "Products" -Id "MyId"
$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
Download a free trial of the Snowflake Data Provider to get started:
Download NowLearn more:
👁 Snowflake Enterprise Data Warehouse IconRapidly create and deploy powerful .NET applications that integrate with Snowflake data warehouse.