Reputation: 117
I am trying to achieve that my output if it is one single line it gets written away in a variable
This is what i have so far
az group list --query '[].{name:name}' --output table
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
az group list --query "[?contains(name, '$filter')].name" --output tsv
what this code does is that you can filter all the resource groups and you get to see the ouptut in a TSV
What i am trying to add is that it checks if it is the only line and then write that line away (if it is one line)
Upvotes: 0
Views: 1321
Reputation: 72171
Since you are already using powershell, why not just use powershell?
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -eq $filter }
Thanks for the help with changing the code! The end result is now:
Connect-AzureRmAccount
(get-azurermresourcegroup).ResourceGroupName
$filter = Read-Host -Prompt "Please filter to find the correct resource group"
$RGName = get-azurermresourcegroup | Where-Object { $_.ResourceGroupName -match $filter }
$RGName.resourcegroupname
Upvotes: 1