Open o-l-a-v opened 1 month ago
Might be relevant: I started researching changing out Search-AzGraph
with Invoke-AzRestMethod
and found that PowerShell could not convert $Response.content
from JSON to PSCustomObject with error:
PS > ConvertFrom-Json -InputObject $Response.'content'
ConvertFrom-Json: The provided JSON includes a property whose name is an empty string, this is only supported using the -AsHashTable switch.
PS >
So the JSON response from the Azure RM API clearly contains a "property whose name is an empty string".
Thanks to EnterprisePolicyAsCode for inspiration. 😊
Another workaround is to exclude properties you're not interested in, hopefully you'll only end up with parsable output.
Example line:
| project id, name, type, location, resourceGroup, subscriptionId, tags
Full example query:
resources
| where type in~ ("Microsoft.Automation/automationAccounts","Microsoft.DataFactory/factories","Microsoft.DocumentDB/databaseAccounts","Microsoft.Logic/workflows","Microsoft.KeyVault/vaults","Microsoft.Network/bastionHosts","Microsoft.Network/networkSecurityGroups","Microsoft.Network/publicIPAddresses","Microsoft.Network/virtualNetworkGateways","Microsoft.ServiceBus/namespaces")
| project id, name, type, location, resourceGroup, subscriptionId, tags
// Add tags from resource group
| join kind = leftouter (
resourcecontainers
| where type == "microsoft.resources/subscriptions/resourcegroups"
| project rgName = name, rgSubscriptionId = subscriptionId, rgTags = tags
) on $left.resourceGroup == $right.rgName and $left.subscriptionId == $right.rgSubscriptionId
| project-away rgName, rgSubscriptionId
// Add tags from subscription
| join kind = leftouter (
resourcecontainers
| where type == "microsoft.resources/subscriptions"
| project subName = name, subId = subscriptionId, subTags = tags
) on $left.subscriptionId == $right.subId
| project-away subId
Let me loop in ResourceGraph team to understand if the JSON response from the Azure RM API clearly contains a "property whose name is an empty string"
is expected behavior.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @venu-l.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @venu-l.
Description
Following query works in Azure Resource Graph Explorer in the Azure portal ( https://portal.azure.com/#view/HubsExtension/ArgQueryBlade ), and if running
Search-AzGraph
with-Debug
I can see that the API returns data.But
Search-AzGraph
fails with error:Issue script & Debug output
Environment data
Module versions
Error output