Azure NetApp Files supports several options for automating processes like deploying a capacity pool or a volume, or changing the size and thereby the performance of a volume. Today, we want to share two example PowerShell scripts that might be useful to you.
You can find a list of all PowerShell and Azure CLI commands for managing Azure NetApp Files in this blog post: https://anfcommunity.com/2020/09/11/powershell-and-cli-for-azure-netapp-files/
Before you can run ANF PowerShell cmdlets, you need to install the ‘AZ’ and ‘AZ.NetAppFiles’ modules. It is recommended to keep the modules up to date, so you can use the latest features.
Install-Module -Name Az -AllowClobber -Force Install-Module -Name Az.NetAppFiles -AllowClobber -Force
The first example script creates a new capacity pool and then deploys an SMB volume within that pool.
# Connect to the Azure account $SubscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" Write-Host "Connecting to Azure subscription $($SubscriptionId)." Connect-AzAccount -Subscription $SubscriptionId # Create new Azure NetApp Files Capacity Pool $AccountName = "anf-eu-west" $Location = "westeurope" $PoolName = "standard" $PoolSizeTiB = 4 # Valid values are 4 to 500 $PoolSizeBytes = $PoolSizeTiB * 1024 * 1024 * 1024 * 1024 $ResourceGroup = "eu-west-anf" $ServiceLevel = "Standard" # Valid values are Standard, Premium and Ultra Write-Host "Creating new ANF capacity pool $($PoolName) with a size of $($PoolSizeTiB) TiB. Service level: $($ServiceLevel)." New-AzNetAppFilesPool -ResourceGroupName $ResourceGroup ` -Location $Location ` -AccountName $AccountName ` -Name $PoolName ` -PoolSize $PoolSizeBytes ` -ServiceLevel $ServiceLevel # Create new Azure NetApp Files Volume $Protocol = "CIFS" # Valid values are CIFS, NFSv3 $VolumeName = "smb01" $VolumePath = "smb01" $VolumeSizeGiB = 1024 # Valid values are 100 (100 GiB) to 102400 (100 TiB) $VolumeSizeBytes = $VolumeSizeGiB * 1024 * 1024 * 1024 $SubnetName = "ANF" $VNetName = "eu-west-hub" $VNet = Get-AzVirtualNetwork -Name $VNetName $Subnet = Get-AzVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $VNet $SubnetId = $Subnet.Id Write-Host "Creating new ANF volume $($VolumeName) with a size of $($VolumeSizeGiB) GiB. Enabling the $($Protocol) protocol on the volume)." New-AzNetAppFilesVolume -ResourceGroupName $ResourceGroup ` -Location $Location ` -AccountName $AccountName ` -PoolName $PoolName ` -Name $VolumeName ` -UsageThreshold $VolumeSizeBytes ` -SubnetId $SubnetId ` -CreationToken $VolumePath ` -ServiceLevel $ServiceLevel ` -ProtocolType $Protocol
Let us take a closer look at how this script works.
First, we need to connect to the Azure subscription by running the Connect-AzAccount cmdlet.
# Connect to the Azure account $SubscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" Write-Host "Connecting to Azure subscription $($SubscriptionId)." Connect-AzAccount -Subscription $SubscriptionId
Once we are connected, we create a new Azure NetApp Files capacity pool. We provide details about the NetApp account name, the region, and the resource group we want to create the account in. We also provide a name of the capacity pool, the size of the pool, and the service level. Note that just a single command is required to create the capacity pool.
# Create new Azure NetApp Files Capacity Pool $AccountName = "anf-eu-west" $Location = "westeurope" $PoolName = "standard" $PoolSizeTiB = 4 # Valid values are 4 to 500 $PoolSizeBytes = $PoolSizeTiB * 1024 * 1024 * 1024 * 1024 $ResourceGroup = "eu-west-anf" $ServiceLevel = "Standard" # Valid values are Standard, Premium and Ultra Write-Host "Creating new ANF capacity pool $($PoolName) with a size of $($PoolSizeTiB) TiB. Service level: $($ServiceLevel)." New-AzNetAppFilesPool -ResourceGroupName $ResourceGroup ` -Location $Location ` -AccountName $AccountName ` -Name $PoolName ` -PoolSize $PoolSizeBytes ` -ServiceLevel $ServiceLevel
After the capacity pool has been created, we deploy a new volume. In this example we create a volume hosting SMB data. A few variables are required: the name, the path, and the size of the volume, and the protocol. Again, it takes just one command to create the volume.
# Create new Azure NetApp Files Volume $Protocol = "CIFS" # Valid values are CIFS, NFSv3 $VolumeName = "smb01" $VolumePath = "smb01" $VolumeSizeGiB = 1024 # Valid values are 100 (100 GiB) to 102400 (100 TiB) $VolumeSizeBytes = $VolumeSizeGiB * 1024 * 1024 * 1024 $SubnetName = "ANF" $VNetName = "eu-west-hub" $VNet = Get-AzVirtualNetwork -Name $VNetName $Subnet = Get-AzVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $VNet $SubnetId = $Subnet.Id Write-Host "Creating new ANF volume $($VolumeName) with a size of $($VolumeSizeGiB) GiB. Enabling the $($Protocol) protocol on the volume)." New-AzNetAppFilesVolume -ResourceGroupName $ResourceGroup ` -Location $Location ` -AccountName $AccountName ` -PoolName $PoolName ` -Name $VolumeName ` -UsageThreshold $VolumeSizeBytes ` -SubnetId $SubnetId ` -CreationToken $VolumePath ` -ServiceLevel $ServiceLevel ` -ProtocolType $Protocol
That’s it! With just three PowerShell cmdlets, you connect to your Azure account, create a capacity pool, and deploy a new volume. It takes just a few minutes until you can consume high performance, low latency storage in Azure.
If you already provisioned a capacity pool and just want to deploy one or several volumes, simply use the second half of the script.
Another common automation use case is resizing a volume for increasing or decreasing the throughput. For example, if you have a batch job that runs every day from 1 am to 4 am and you want to speed this up, you can simply run the following script before and after the batch jobs runs.
# Connect to the Azure account $SubscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" Write-Host "Connecting to Azure subscription $($SubscriptionId)." Connect-AzAccount -Subscription $SubscriptionId # Modify volume throughput by changing the volume size $AccountName = "anf-eu-west" $Location = "westeurope" $PoolName = "standard" $ResourceGroup = "eu-west-anf" $VolumeName = "smb01" $VolumeSizeGiB = 4096 # Valid values are 100 (100 GiB) to 102400 (100 TiB) $VolumeSizeBytes = $VolumeSizeGiB * 1024 * 1024 * 1024 $Vol = Get-AzNetAppFilesVolume -ResourceGroupName $ResourceGroup -AccountName $AccountName -PoolName $PoolName -Name $VolumeName Write-Host "Changing size of ANF volume $($VolumeName) from $($Vol.UsageThreshold/1GB) GiB to $($VolumeSizeGiB) GiB." Update-AzNetAppFilesVolume -ResourceGroupName $ResourceGroup ` -Location $Location ` -AccountName $AccountName ` -PoolName $PoolName ` -Name $VolumeName ` -UsageThreshold $VolumeSizeBytes
If your volume size is 2 TiB and you need twice the throughput, set the $VolumeSizeGiB variable to 4096, like in the example above. Once the batch job has completed, set the $VolumeSizeGiB variable back to 2048 and run the script again.
Hi Dirk,
Thanks for sharing the nice blog. I tried the given ps script to create the ANF volume but it’s not working. Getting the error related to export policy because script does not contain export policy parameter and ANF volume must have at least default export policy.
Hi Shavez, that is correct this script example is focussing on SMB protocol. If you want to create an NFSv3/v4.1 volume you need to add : az netappfiles volume export-policy add
https://docs.microsoft.com/en-us/cli/azure/netappfiles/volume/export-policy?view=azure-cli-latest#az_netappfiles_volume_export_policy_list
NFS is no longer a valid value for protocol.
NFSv3 works
Hi David, thanks for pointing that out you are correct 🙂 I have adjusted it.
NFSv4.1 has been added as a ProtocolType as well now.