Enable everyone in your organization to access their data in the cloud — no code required.
Learn More →Automate Azure Analysis Services Integration Tasks from PowerShell
Are you looking for a quick and easy way to access Azure Analysis Services data from PowerShell? We show how to use the Cmdlets for Azure Analysis Services and the CData ADO.NET Provider for Azure Analysis Services to connect to Azure Analysis Services data and synchronize, automate, download, and more.
The CData Cmdlets for Azure Analysis Services are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Azure Analysis Services.
Cmdlets or ADO.NET?
The cmdlets are not only a PowerShell interface to the Azure Analysis Services API, but also an SQL interface; this tutorial shows how to use both to retrieve Azure Analysis Services data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Azure Analysis Services. To access Azure Analysis Services data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Azure Analysis Services.
After obtaining the needed connection properties, accessing Azure Analysis Services data in PowerShell consists of three basic steps.
To connect to Azure Analysis Services, set the Url property to a valid server, for instance, asazure://southcentralus.asazure.windows.net/server, in addition to authenticating. Optionally, set Database to distinguish which Azure database on the server to connect to.
Azure Analysis Services uses the OAuth authentication standard. OAuth requires the authenticating user to interact with Azure Analysis Services using the browser. You can connect without setting any connection properties for your user credentials. See the Help documentation for more information.
PowerShell
-
Install the module:
Install-Module AASCmdlets
-
Connect:
$aas = Connect-AAS -URL "$URL"
-
Search for and retrieve data:
$country = "Australia" $customer = Select-AAS -Connection $aas -Table "Customer" -Where "Country = `'$Country`'" $customer
You can also use the Invoke-AAS cmdlet to execute SQL commands:
$customer = Invoke-AAS -Connection $aas -Query 'SELECT * FROM Customer WHERE Country = @Country' -Params @{'@Country'='Australia'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Azure Analysis Services\lib\System.Data.CData.AAS.dll")
-
Connect to Azure Analysis Services:
$conn= New-Object System.Data.CData.AAS.AASConnection("URL=asazure://REGION.asazure.windows.net/server;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the AASDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Country, Education from Customer" $da= New-Object System.Data.CData.AAS.AASDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.country $_.education }