使用 Azure PowerShell 開始使用 Azure Data Lake AnalyticsGet started with Azure Data Lake Analytics using Azure PowerShell

了解如何使用 Azure PowerShell 建立 Azure Data Lake Analytics 帳戶,然後提交和執行 U-SQL 作業。Learn how to use Azure PowerShell to create Azure Data Lake Analytics accounts and then submit and run U-SQL jobs. 如需有關 Data Lake Analytics 的詳細資訊,請參閱 Azure Data Lake Analytics 概觀For more information about Data Lake Analytics, see Azure Data Lake Analytics overview.

必要條件Prerequisites

注意

本文已更新為使用新的 Azure PowerShell Az 模組。This article has been updated to use the new Azure PowerShell Az module. AzureRM 模組在至少 2020 年 12 月之前都還會持續收到錯誤 (Bug) 修正,因此您仍然可以持續使用。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要深入了解新的 Az 模組和 AzureRM 的相容性,請參閱新的 Azure PowerShell Az 模組簡介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 如需 Az 模組安裝指示,請參閱安裝 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

開始進行本教學課程之前,您必須具備下列資訊:Before you begin this tutorial, you must have the following information:

登入 AzureLog in to Azure

本教學課程假設您已熟悉如何使用 Azure PowerShell。This tutorial assumes you are already familiar with using Azure PowerShell. 特別是,您需要了解如何登入 Azure。In particular, you need to know how to log in to Azure. 如果您需要協助,請參閱開始使用 Azure PowerShellSee the Get started with Azure PowerShell if you need help.

若要使用訂用帳戶名稱登入:To log in with a subscription name:

Connect-AzAccount -SubscriptionName "ContosoSubscription"

除了訂用帳戶名稱之外,您也可以使用訂用帳戶識別碼來登入:Instead of the subscription name, you can also use a subscription id to log in:

Connect-AzAccount -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

如果成功,這個命令的輸出看起來會類似下列文字:If successful, the output of this command looks like the following text:

Environment           : AzureCloud
Account               : joe@contoso.com
TenantId              : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
SubscriptionId        : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
SubscriptionName      : ContosoSubscription
CurrentStorageAccount :

準備教學課程Preparing for the tutorial

本教學課程中的 PowerShell 程式碼片段會使用這些變數來儲存此資訊:The PowerShell snippets in this tutorial use these variables to store this information:

$rg = "<ResourceGroupName>"
$adls = "<DataLakeStoreAccountName>"
$adla = "<DataLakeAnalyticsAccountName>"
$location = "East US 2"

取得 Data Lake Analytics 帳戶的相關資訊Get information about a Data Lake Analytics account

Get-AdlAnalyticsAccount -ResourceGroupName $rg -Name $adla  

提交 U-SQL 作業Submit a U-SQL job

建立 PowerShell 變數,可保留 U-SQL 指令碼。Create a PowerShell variable to hold the U-SQL script.

$script = @"
@a  = 
    SELECT * FROM 
        (VALUES
            ("Contoso", 1500.0),
            ("Woodgrove", 2700.0)
        ) AS 
              D( customer, amount );
OUTPUT @a
    TO "/data.csv"
    USING Outputters.Csv();

"@

使用 Submit-AdlJob Cmdlet 和 -Script 參數提交指令碼文字。Submit the script text with the Submit-AdlJob cmdlet and the -Script parameter.

$job = Submit-AdlJob -Account $adla -Name "My Job" -Script $script

或者,您也可以使用 -ScriptPath 參數提交指令檔:As an alternative, you can submit a script file using the -ScriptPath parameter:

$filename = "d:\test.usql"
$script | out-File $filename
$job = Submit-AdlJob -Account $adla -Name "My Job" -ScriptPath $filename

使用 Get-AdlJob 取得作業狀態。Get the status of a job with Get-AdlJob.

$job = Get-AdlJob -Account $adla -JobId $job.JobId

使用 Wait-AdlJob Cmdlet,而不是一再呼叫 Get-AdlJob 直到作業完成。Instead of calling Get-AdlJob over and over until a job finishes, use the Wait-AdlJob cmdlet.

Wait-AdlJob -Account $adla -JobId $job.JobId

使用 Export-AdlStoreItem 下載輸出檔案。Download the output file using Export-AdlStoreItem.

Export-AdlStoreItem -Account $adls -Path "/data.csv" -Destination "C:\data.csv"

另請參閱See also