32
loading...
This website collects cookies to deliver better user experience
Install-Module -Name Az.ResourceGraph -Scope CurrentUser
resources
| where type =~ 'Microsoft.Compute/virtualMachines'
Search-AzGraph -Query "resources | where type =~ 'Microsoft.Compute/virtualMachines'"
(Search-AzGraph -Query "resources | where type =~ 'Microsoft.Compute/virtualMachines'").data
$PSDefaultParameterValues=@{"Search-AzGraph:Subscription"= $(Get-AzSubscription).ID}
Search-AzGraph -Query "Resources" -Subscription @('xxxxx-xxxx-xxxx-xxxx','xxxxx-xxxx-xxxx-xxxx'')
resources | limit 10
Search-AzGraph -Query "Resource"
Search-AzGraph: {
"error": {
"code": "BadRequest",
"message": "Please provide below info when asking for support: timestamp = 2021-07-04T09:35:16.1689113Z, correlationId = a9447f06-5912-46cd-8907-7b430fcd8a98.",
"details": [
{
"code": "DisallowedLogicalTableName",
"message": "Table Resource is invalid, unsupported or disallowed."
}
]
}
}
class AzResourceGraphException : Exception {
[string] $additionalData
AzResourceGraphException($Message, $additionalData) : base($Message) {
$this.additionalData = $additionalData
}
}
$resourceGraphQuery = "Resource"
Search-AzGraph -Query $resourceGraphQuery -ErrorVariable grapherror -ErrorAction SilentlyContinue
if ($null -ne $grapherror.Length) {
$errorJSON = $grapherror.ErrorDetails.Message | ConvertFrom-Json
throw [AzResourceGraphException]::new($errorJSON.error.details.code, $errorJSON.error.details.message)
}
class AzResourceGraphException : Exception {
[string] $additionalData
AzResourceGraphException($Message, $additionalData) : base($Message) {
$this.additionalData = $additionalData
}
}
try {
$resourceGraphQuery = "Resource"
Search-AzGraph -Query $resourceGraphQuery -ErrorVariable grapherror -ErrorAction SilentlyContinue
if ($null -ne $grapherror.Length) {
$errorJSON = $grapherror.ErrorDetails.Message | ConvertFrom-Json
throw [AzResourceGraphException]::new($errorJSON.error.details.code, $errorJSON.error.details.message)
}
}
catch [AzResourceGraphException] {
Write-Host "An error on KQL query"
Write-Host $_.Exception.message
Write-Host $_.Exception.additionalData
}
catch {
Write-Host "An error occurred in the script"
Write-Host $_.Exception.message
}
32