I am trying to get the list of storages name for a specific subscription using powershell. If I have the correct subscription name, I get the result but if there is some mistype then I get this error:
Select-AzSubscription : Please provide a valid tenant or a valid subscription. Select-AzSubscription -SubscriptionName $subName CategoryInfo : CloseError: (:) [Set-AzContext], ArgumentException FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
What would be the best option to handle the error message and exit out from the script with a message "Couldn't find the subscription". Here is the powershell code:
###Set a subscription name
$subName = "Test SubscriptionName"
Select-AzSubscription -SubscriptionName $subName
### Select storage accounts based for above subscription
$sAccount = Get-AzStorageAccount | select StorageAccountName
$sAccount