Automation PowerShell

Azure NetApp Files: PowerShell One-Liners

Let’s expand on this great post by my colleague, Yassir Halim. These are some more advanced PowerShell commands that take advantage of PowerShell’s pipeline and even get data from Azure Monitor to show us things like volume consumed sizes. I’ll add to this list as I find or create more useful one-liners.

Would you like to contribute to this list? Comment below with your favorite one-liner and we’ll get it added to the list.

Here we go!

list all ANF resources

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp*'} | Format-Table

list all ANF NetApp accounts

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts'} | Format-Table

list all ANF capacity pools

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools'} | Format-Table

list all ANF volumes

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'} | Format-Table

get details of all ANF capacity pools

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools'} | Get-AzNetAppFilesPool

list all ANF volumes matching a ‘creator’ tag of ‘luces’

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes' -and $_.Tags.creator -eq "luces"}

get select details of all ANF volumes and display as a table

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'} | Get-AzNetAppFilesVolume | select Name, ResourceGroupName, ServiceLevel, UsageThreshold, ThroughputMibps | Format-Table

get select details of all ANF volumes with a shorter version of the volume name and display as a table

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'} | Get-AzNetAppFilesVolume | select @{Name='ShortName'; Expression={$_.Name.split('/')[2]}}, ResourceGroupName, ServiceLevel, UsageThreshold, ThroughputMibps | ft

get select details of all ANF volumes with size displayed as GiB and display as a table

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'} | Get-AzNetAppFilesVolume | select @{Name='ShortName'; Expression={$_.Name.split('/')[2]}}, ResourceGroupName, ServiceLevel, @{Name='SizeGiB'; Expression={$_.UsageThreshold / 1024 / 1024 / 1024}} | ft

get select details of all ANF volumes including consumed sizes from Get-AzMetric and display as a table

Get-AzResource | Where-Object {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'} | Get-AzNetAppFilesVolume | Select-Object @{Name='ShortName'; Expression={$_.Name.split('/')[2]}}, @{Name='SizeGiB'; Expression={$_.UsageThreshold / 1024 / 1024 / 1024}}, @{Name='ConsumedGiB'; Expression={[math]::Round($((Get-AzMetric -ResourceId $_.Id -MetricName 'VolumeLogicalSize' -StartTime $(get-date).AddMinutes(-15) -EndTime $(get-date) -TimeGrain 00:5:00 -WarningAction SilentlyContinue | Select-Object -ExpandProperty data | Select-Object -ExpandProperty Average) | Measure-Object -average).average / 1024 / 1024 / 1024, 2)}} | Format-Table 

list all ANF snapshot policies and display as a table

Get-AzResource | ? {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/snapshotPolicies'} | ft

Need a specific Azure NetApp Files one-liner, but can’t quite figure it out? Let us know in the comments and we’ll try to assist.

Thank you for reading and happy PoShing!

Leave a Reply

%d bloggers like this: