Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Automate Azure Table Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Azure Table data from PowerShell? This article demonstrates how to utilize the Azure Table Cmdlets for tasks like connecting to Azure Table data, automating operations, downloading data, and more.
The CData ADO.NET Provider for Azure is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Azure Table.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Azure Table; this tutorial shows how to use the Provider to create, retrieve, update, and delete Azure Table data.
Once you have acquired the necessary connection properties, accessing Azure Table data in PowerShell can be enabled in three steps.
Specify your AccessKey and your Account to connect. Set the Account property to the Storage Account Name and set AccessKey to one of the Access Keys. Either the Primary or Secondary Access Keys can be used. To obtain these values, navigate to the Storage Accounts blade in the Azure portal. You can obtain the access key by selecting your account and clicking Access Keys in the Settings section.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Azure\lib\System.Data.CData.AzureTables.dll")
-
Connect to Azure Table:
$conn= New-Object System.Data.CData.AzureTables.AzureTablesConnection("AccessKey=myAccessKey;Account=myAccountName;") $conn.Open()
-
Instantiate the AzureTablesDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, Price from NorthwindProducts" $da= New-Object System.Data.CData.AzureTables.AzureTablesDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.price }
Update Azure Table Data
$cmd = New-Object System.Data.CData.AzureTables.AzureTablesCommand("UPDATE NorthwindProducts SET ShipCity='New York' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.AzureTables.AzureTablesParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Azure Table Data
$cmd = New-Object System.Data.CData.AzureTables.AzureTablesCommand("INSERT INTO NorthwindProducts (ShipCity) VALUES (@myShipCity)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.AzureTables.AzureTablesParameter("@myShipCity","New York")))
$cmd.ExecuteNonQuery()
Delete Azure Table Data
$cmd = New-Object System.Data.CData.AzureTables.AzureTablesCommand("DELETE FROM NorthwindProducts WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.AzureTables.AzureTablesParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject