az resource delete --resource-group $ResourceGroupName --ids $azCliIds fails
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
I'm trying to use delete command of az cli and pass it a list of ids built by powershell
This is the code
```
$AzureResources = (az resource list --resource-group $ResourceGroupName | ConvertFrom-Json).where({ $_.name.contains($AzureResourcePrefix) })
$ids = $AzureResources.ForEach({$_.id})
$azCliIds = ""
foreach ($id in $ids) {
$azCliIds += $id + ' '
}
$azCliIds = $azCliIds.TrimEnd()
az resource delete --resource-group $ResourceGroupName --ids $azCliIds --debug
```
I get this error
```
cli.azure.cli.command_modules.resource.custom: (ResourceNotFound) The Resource 'Microsoft.Web/serverFarms/xxxx-asp-rad-we ' under resource group 'xxx-rad-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.Web/serverFarms/xxxx-asp-rad-we ' under resource group 'xxxx-rad-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
```
The error is wrong because the ids are built from az itself.
If I take literally paste the results of $azCliIds then it works fine, i.e.
```
az resource delete --resource-group $ResourceGroupName --ids /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/xxxxx-rad-rg/providers/Microsoft.Web/serverFarms/pltfrm-asp-rad-we /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/pltfrm-rad-rg/providers/Microsoft.Web/sites/xxxx-wa-ocelot-rad-we /subscriptions/xxxxxxxxxxxxxxxxx/resourceGroups/pltfrm-rad-rg/providers/Microsoft.Web/sites/xxxxxx-wa-ocelot-rad-we/slots/slot1 --debug
```
It appears if ids contain any type of quote around it the cli doesn't like it.
If $azCliIds contains a single item then it works as well
Contributor guide
Assessment
This issue has not been assessed yet.