ODataQuery parametr of Get-AzureRmResource still fails to add $filter properly
Cmdlet(s)
PowerShell Version
PSVersion 5.0.10586.117
Module Version
Get-AzureRmResource : 4.0.0 : AzureRM.Resources
OS Version
10.0.10586.117
Description
$RateCardApiVersion = "2015-06-01-preview"
$Currency = ‘USD’
$Locale = ‘en-US’
$RegionInfo = ‘US’
$OfferDurableId = ‘MS-AZR-0003P’
$subscriptionId = 'some GUID'
$uri = "/subscriptions/{0}/providers/Microsoft.Commerce/RateCard" -f $subscriptionId
$query = "`$filter=OfferDurableId eq '{0}' and Currency eq '{1}' and Locale eq '{2}' and RegionInfo eq '{3}'" -f $OfferDurableId, $Currency, $Locale, $RegionInfo
Get-AzureRmResource -ResourceId $uri -ApiVersion $RateCardApiVersion -ODataQuery $query -Debug -Verbose
This fails with Get-AzureRmResource : {"Message":"Invalid query specified. Please specify a valid filter in format of $filter"}
Debug Output
in the debug output I see the following the request URI seems to be wrong, it misses $filter completely
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/some guid/providers/Microsoft.Commerce/RateCard?OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq
'US'&api-version=2015-06-01-preview
Headers:
User-Agent : AzurePowershell/v4.0.0.0,PSVersion/v5.0.10586.117
ParameterSetName : Get a single resource by its Id.
CommandName : Get-AzureRmResource
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Script/Steps for Reproduction
I see the same problem, accept I don't get any errors. In my case the $filter= is just removed. However, you can trick it to work. This is what I did: $foo=bar&$filter=. It seems the filter is busted only when it is the first parameter.
@TianoMS Hey Tian, would you mind taking a look at this issue?
Looks like a bug in Get-AzureRmResource. Add @ravbhatnagar to triage.
@eosfor hit the same issue, after hacking it a bit it seems like an encoding issue, worked around passing filter like this
%24filter=...
@TarasRoshko - awesome workaround, I have spent a couple of hours trying various different workaround before I stumbled across this thread.
@Tiano2017 would you mind taking a look at this issue?
:bell: Routing this issue to @act-identity-squad.
This scenario targets the retired Microsoft.Commerce/RateCard preview API and the retired Get-AzureRmResource cmdlet, and does not reproduce as filed. If you hit issues with -ODataQuery on current Get-AzResource against a supported API, please open a fresh issue with the exact command and -Debug output.