Get started with Azure Data Lake Storage Gen1 using Azure PowerShell
Azure Data Lake Storage Gen2 is now generally available. We recommend that you start using it today. For more information, see the product page.
Learn how to use Azure PowerShell to create an Azure Data Lake Storage Gen1 account and perform basic operations such as create folders, upload and download data files, delete your account, etc. For more information about Data Lake Storage Gen1, see Overview of Data Lake Storage Gen1.
This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.
- An Azure subscription. See Get Azure free trial.
- Azure PowerShell 1.0 or greater. See How to install and configure Azure PowerShell.
This article uses a simpler authentication approach with Data Lake Storage Gen1 where you are prompted to enter your Azure account credentials. The access level to Data Lake Storage Gen1 account and file system is then governed by the access level of the logged in user. However, there are other approaches as well to authenticate with Data Lake Storage Gen1, which are end-user authentication or service-to-service authentication. For instructions and more information on how to authenticate, see End-user authentication or Service-to-service authentication.
Create a Data Lake Storage Gen1 account
From your desktop, open a new Windows PowerShell window. Enter the following snippet to log in to your Azure account, set the subscription, and register the Data Lake Storage Gen1 provider. When prompted to log in, make sure you log in as one of the subscription administrators/owner:
# Log in to your Azure account Connect-AzAccount # List all the subscriptions associated to your account Get-AzSubscription # Select a subscription Set-AzContext -SubscriptionId <subscription ID> # Register for Azure Data Lake Storage Gen1 Register-AzResourceProvider -ProviderNamespace "Microsoft.DataLakeStore"
A Data Lake Storage Gen1 account is associated with an Azure Resource Group. Start by creating an Azure Resource Group.
$resourceGroupName = "<your new resource group name>" New-AzResourceGroup -Name $resourceGroupName -Location "East US 2"
Create a Data Lake Storage Gen1 account. The name you specify must only contain lowercase letters and numbers.
$dataLakeStorageGen1Name = "<your new Data Lake Storage Gen1 account name>" New-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $dataLakeStorageGen1Name -Location "East US 2"
Verify that the account is successfully created.
Test-AzDataLakeStoreAccount -Name $dataLakeStorageGen1Name
The output for the cmdlet should be True.
Create directory structures in your Data Lake Storage Gen1 account
You can create directories under your Data Lake Storage Gen1 account to manage and store data.
Specify a root directory.
$myrootdir = "/"
Create a new directory called mynewdirectory under the specified root.
New-AzDataLakeStoreItem -Folder -AccountName $dataLakeStorageGen1Name -Path $myrootdir/mynewdirectory
Verify that the new directory is successfully created.
Get-AzDataLakeStoreChildItem -AccountName $dataLakeStorageGen1Name -Path $myrootdir
It should show an output as shown in the following screenshot:
Upload data to your Data Lake Storage Gen1 account
You can upload your data to Data Lake Storage Gen1 directly at the root level, or to a directory that you created within the account. The snippets in this section demonstrate how to upload some sample data to the directory (mynewdirectory) you created in the previous section.
If you are looking for some sample data to upload, you can get the Ambulance Data folder from the Azure Data Lake Git Repository. Download the file and store it in a local directory on your computer, such as C:\sampledata.
Import-AzDataLakeStoreItem -AccountName $dataLakeStorageGen1Name -Path "C:\sampledata\vehicle1_09142014.csv" -Destination $myrootdir\mynewdirectory\vehicle1_09142014.csv
Rename, download, and delete data from your Data Lake Storage Gen1 account
To rename a file, use the following command:
Move-AzDataLakeStoreItem -AccountName $dataLakeStorageGen1Name -Path $myrootdir\mynewdirectory\vehicle1_09142014.csv -Destination $myrootdir\mynewdirectory\vehicle1_09142014_Copy.csv
To download a file, use the following command:
Export-AzDataLakeStoreItem -AccountName $dataLakeStorageGen1Name -Path $myrootdir\mynewdirectory\vehicle1_09142014_Copy.csv -Destination "C:\sampledata\vehicle1_09142014_Copy.csv"
To delete a file, use the following command:
Remove-AzDataLakeStoreItem -AccountName $dataLakeStorageGen1Name -Paths $myrootdir\mynewdirectory\vehicle1_09142014_Copy.csv
When prompted, enter Y to delete the item. If you have more than one file to delete, you can provide all the paths separated by comma.
Remove-AzDataLakeStoreItem -AccountName $dataLakeStorageGen1Name -Paths $myrootdir\mynewdirectory\vehicle1_09142014.csv, $myrootdir\mynewdirectoryvehicle1_09142014_Copy.csv
Delete your Data Lake Storage Gen1 account
Use the following command to delete your Data Lake Storage Gen1 account.
Remove-AzDataLakeStoreAccount -Name $dataLakeStorageGen1Name
When prompted, enter Y to delete the account.