Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Deze pagina is een verzameling azure Resource Graph-voorbeeldquery's voor Azure Virtual Machines.
Voorbeeldvragen
Aantal installatie van besturingssysteemupdate voltooid
Retourneert een lijst met status van de installatie van besturingssysteemupdates die in de afgelopen zeven dagen zijn uitgevoerd voor uw computers.
PatchAssessmentResources
| where type !has 'softwarepatches'
| extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4))
| extend prop = parse_json(properties)
| extend lTime = todatetime(prop.lastModifiedDateTime), OS = tostring(prop.osType), installedPatchCount = tostring(prop.installedPatchCount), failedPatchCount = tostring(prop.failedPatchCount), pendingPatchCount = tostring(prop.pendingPatchCount), excludedPatchCount = tostring(prop.excludedPatchCount), notSelectedPatchCount = tostring(prop.notSelectedPatchCount)
| where lTime > ago(7d)
| project lTime, RunID=name,machineName, rgName, resourceType, OS, installedPatchCount, failedPatchCount, pendingPatchCount, excludedPatchCount, notSelectedPatchCount
az graph query -q "PatchAssessmentResources | where type !has 'softwarepatches' | extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)) | extend prop = parse_json(properties) | extend lTime = todatetime(prop.lastModifiedDateTime), OS = tostring(prop.osType), installedPatchCount = tostring(prop.installedPatchCount), failedPatchCount = tostring(prop.failedPatchCount), pendingPatchCount = tostring(prop.pendingPatchCount), excludedPatchCount = tostring(prop.excludedPatchCount), notSelectedPatchCount = tostring(prop.notSelectedPatchCount) | where lTime > ago(7d) | project lTime, RunID=name,machineName, rgName, resourceType, OS, installedPatchCount, failedPatchCount, pendingPatchCount, excludedPatchCount, notSelectedPatchCount"
Aantal virtuele machines op beschikbaarheidsstatus en abonnements-id
Retourneert het aantal virtuele machines (type Microsoft.Compute/virtualMachines
) dat is geaggregeerd op basis van de beschikbaarheidsstatus voor elk van uw abonnementen.
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| summarize count() by subscriptionId, AvailabilityState = tostring(properties.availabilityState)
az graph query -q "HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | summarize count() by subscriptionId, AvailabilityState = tostring(properties.availabilityState)"
Aantal virtuele machines op energiestatus
Retourneert het aantal virtuele machines (type Microsoft.Compute/virtualMachines
) dat is gecategoriseerd op basis van de energiestatus. Zie voor meer informatie over energiestatussen de Overzicht van energiestatussen.
Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by PowerState = tostring(properties.extended.instanceView.powerState.code)
az graph query -q "Resources | where type == 'microsoft.compute/virtualmachines' | summarize count() by PowerState = tostring(properties.extended.instanceView.powerState.code)"
Virtuele machines tellen per besturingssysteemtype
Voortbouwend op de vorige query zijn we nog steeds een grens aan het stellen aan het aantal Azure-resources van het type Microsoft.Compute/virtualMachines
, maar beperken we niet langer het aantal geretourneerde records. In plaats daarvan hebben we summarize
en count()
gebruikt om te definiëren hoe we de waarden willen groeperen en aggregeren op basis van de eigenschap. In dit voorbeeld is dat properties.storageProfile.osDisk.osType
. Voor een voorbeeld van hoe deze tekenreeks er uitziet in het volledige object, raadpleegt u Resources verkennen - detectie van virtuele machines.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| summarize count() by tostring(properties.storageProfile.osDisk.osType)
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
Virtuele machines tellen op besturingssysteemtype met de extend-opdracht
Een andere manier om de query 'Aantal virtuele machines per type besturingssysteem' te schrijven, is door een eigenschap en deze een tijdelijke naam te extend
geven voor gebruik in de query, in dit geval het besturingssysteem. besturingssysteem wordt vervolgens gebruikt door summarize
en count()
zoals in het voorbeeld waarnaar wordt verwezen.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| extend os = properties.storageProfile.osDisk.osType
| summarize count() by tostring(os)
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | extend os = properties.storageProfile.osDisk.osType | summarize count() by tostring(os)"
Alle nieuwe waarschuwingen van de afgelopen 30 dagen ophalen
Deze query bevat een lijst met alle nieuwe waarschuwingen van de gebruiker, van de afgelopen 30 dagen.
iotsecurityresources
| where type == 'microsoft.iotsecurity/locations/devicegroups/alerts'
| where todatetime(properties.startTimeUtc) > ago(30d) and properties.status == 'New'
az graph query -q "iotsecurityresources | where type == 'microsoft.iotsecurity/locations/devicegroups/alerts' | where todatetime(properties.startTimeUtc) > ago(30d) and properties.status == 'New'"
Capaciteit en grootte van een virtuele-machineschaalset ophalen
Met deze query zoekt u naar resources voor schaalsets van virtuele machines en verkrijgt u verschillende details, waaronder de grootte van de virtuele machine en de capaciteit van de schaalset. Deze query maakt gebruik van de functie toint()
om de capaciteit te converteren naar een waarde die kan worden gesorteerd. Ten slotte worden de kolommen hernoemd naar eigenschappen met aangepaste namen.
Resources
| where type=~ 'microsoft.compute/virtualmachinescalesets'
| where name contains 'contoso'
| project subscriptionId, name, location, resourceGroup, Capacity = toint(sku.capacity), Tier = sku.name
| order by Capacity desc
az graph query -q "Resources | where type=~ 'microsoft.compute/virtualmachinescalesets' | where name contains 'contoso' | project subscriptionId, name, location, resourceGroup, Capacity = toint(sku.capacity), Tier = sku.name | order by Capacity desc"
Alle extensies weergeven die zijn geïnstalleerd op een virtuele machine
Ten eerste gebruikt deze query extend
op het resourcetype virtuele machines om de ID in hoofdletters op te halen (toupper()
), de naam en het type van het besturingssysteem op te halen en de grootte van de virtuele machine op te halen. Het verkrijgen van de resource-id in hoofdletters is een goede manier om te koppelen aan een andere eigenschap. Vervolgens gebruikt de query join
met kind
als leftouter
om extensies voor virtuele machines op te halen door een hoofdletter substring
van de extensie-ID te matchen. Het gedeelte van de ID voor /extensions/\<ExtensionName\>
heeft dezelfde indeling als de ID van de virtuele machine, dus gebruiken we deze eigenschap voor join
.
summarize
wordt vervolgens gebruikt met make_list
de naam van de extensie van de virtuele machine om de naam van elke extensie te combineren waarbij id, OSName, OSType en VMSize hetzelfde zijn in één matrixeigenschap. Ten slotte zetten we order by
OSName om naar kleine letters met asc
.
order by
is standaard aflopend.
Resources
| where type == 'microsoft.compute/virtualmachines'
| extend
JoinID = toupper(id),
OSName = tostring(properties.osProfile.computerName),
OSType = tostring(properties.storageProfile.osDisk.osType),
VMSize = tostring(properties.hardwareProfile.vmSize)
| join kind=leftouter(
Resources
| where type == 'microsoft.compute/virtualmachines/extensions'
| extend
VMId = toupper(substring(id, 0, indexof(id, '/extensions'))),
ExtensionName = name
) on $left.JoinID == $right.VMId
| summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize
| order by tolower(OSName) asc
az graph query -q "Resources | where type == 'microsoft.compute/virtualmachines' | extend JoinID = toupper(id), OSName = tostring(properties.osProfile.computerName), OSType = tostring(properties.storageProfile.osDisk.osType), VMSize = tostring(properties.hardwareProfile.vmSize) | join kind=leftouter( Resources | where type == 'microsoft.compute/virtualmachines/extensions' | extend VMId = toupper(substring(id, 0, indexof(id, '/extensions'))), ExtensionName = name ) on \$left.JoinID == \$right.VMId | summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize | order by tolower(OSName) asc"
Beschikbare besturingssysteemupdates weergeven voor al uw computers gegroepeerd op updatecategorie
Retourneert een lijst met besturingssystemen die in afwachting zijn voor uw machines.
PatchAssessmentResources
| where type !has 'softwarepatches'
| extend prop = parse_json(properties)
| extend lastTime = properties.lastModifiedDateTime
| extend updateRollupCount = prop.availablePatchCountByClassification.updateRollup, featurePackCount = prop.availablePatchCountByClassification.featurePack, servicePackCount = prop.availablePatchCountByClassification.servicePack, definitionCount = prop.availablePatchCountByClassification.definition, securityCount = prop.availablePatchCountByClassification.security, criticalCount = prop.availablePatchCountByClassification.critical, updatesCount = prop.availablePatchCountByClassification.updates, toolsCount = prop.availablePatchCountByClassification.tools, otherCount = prop.availablePatchCountByClassification.other, OS = prop.osType
| project lastTime, id, OS, updateRollupCount, featurePackCount, servicePackCount, definitionCount, securityCount, criticalCount, updatesCount, toolsCount, otherCount
az graph query -q "PatchAssessmentResources | where type !has 'softwarepatches' | extend prop = parse_json(properties) | extend lastTime = properties.lastModifiedDateTime | extend updateRollupCount = prop.availablePatchCountByClassification.updateRollup, featurePackCount = prop.availablePatchCountByClassification.featurePack, servicePackCount = prop.availablePatchCountByClassification.servicePack, definitionCount = prop.availablePatchCountByClassification.definition, securityCount = prop.availablePatchCountByClassification.security, criticalCount = prop.availablePatchCountByClassification.critical, updatesCount = prop.availablePatchCountByClassification.updates, toolsCount = prop.availablePatchCountByClassification.tools, otherCount = prop.availablePatchCountByClassification.other, OS = prop.osType | project lastTime, id, OS, updateRollupCount, featurePackCount, servicePackCount, definitionCount, securityCount, criticalCount, updatesCount, toolsCount, otherCount"
Lijst van geïnstalleerde updates voor Linux-besturingssysteem
Retourneert een lijst met status van Linux Server: installatie van besturingssysteemupdates uitgevoerd voor uw computers in de afgelopen zeven dagen.
PatchAssessmentResources
| where type has 'softwarepatches' and properties has 'version'
| extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10))
| extend prop = parse_json(properties)
| extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), version = tostring(prop.version), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications)
| where lTime > ago(7d)
| project lTime, RunID, machineName, rgName, resourceType, patchName, version, classifications, installationState
| sort by RunID
az graph query -q "PatchAssessmentResources | where type has 'softwarepatches' and properties has 'version' | extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10)) | extend prop = parse_json(properties) | extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), version = tostring(prop.version), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications) | where lTime > ago(7d) | project lTime, RunID, machineName, rgName, resourceType, patchName, version, classifications, installationState | sort by RunID"
Lijst met virtuele machines en bijbehorende beschikbaarheidsstatussen per resource-id
Retourneert de meest recente lijst met virtuele machines (type Microsoft.Compute/virtualMachines
) geaggregeerd op beschikbaarheidsstatus. De query biedt ook de bijbehorende resource-ID op basis van properties.targetResourceId
, voor eenvoudige foutopsporing en mitigatie. Beschikbaarheidsstatussen kunnen een van de vier waarden zijn: Beschikbaar, Niet beschikbaar, Gedegradeerd en Onbekend. Zie het overzicht van Azure Resource Health voor meer informatie over wat elk van de beschikbaarheidsstatussen betekent.
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)
az graph query -q "HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)"
Lijst met virtuele machines op beschikbaarheidsstatus en energiestatus met resource-id's en resourcegroepen
Retourneert een lijst met virtuele machines (type Microsoft.Compute/virtualMachines
) die zijn geaggregeerd op hun energiestatus en beschikbaarheidsstatus om een samenhangende status voor uw virtuele machines te bieden. De query bevat ook details over de resourcegroep en resource-id die aan elke vermelding zijn gekoppeld voor gedetailleerde zichtbaarheid van uw resources.
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| project resourceGroup, Id = tolower(id), PowerState = tostring( properties.extended.instanceView.powerState.code)
| join kind=leftouter (
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| where tostring(properties.targetResourceType) =~ 'microsoft.compute/virtualmachines'
| project targetResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState))
on $left.Id == $right.targetResourceId
| project-away targetResourceId
| where PowerState != 'PowerState/deallocated'
az graph query -q "Resources | where type =~ 'microsoft.compute/virtualmachines' | project resourceGroup, Id = tolower(id), PowerState = tostring( properties.extended.instanceView.powerState.code) | join kind=leftouter ( HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | where tostring(properties.targetResourceType) =~ 'microsoft.compute/virtualmachines' | project targetResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)) on \$left.Id == \$right.targetResourceId | project-away targetResourceId | where PowerState != 'PowerState/deallocated'"
Lijst met virtuele machines die niet beschikbaar zijn op basis van Resource-ID's
Retourneert de meest recente lijst met virtuele machines (type Microsoft.Compute/virtualMachines
) die zijn geaggregeerd op basis van de beschikbaarheidsstatus. In de ingevulde lijst worden alleen virtuele machines gemarkeerd waarvan de beschikbaarheidsstatus niet beschikbaar is om ervoor te zorgen dat u op de hoogte bent van alle statussen waarin uw virtuele machines zich bevinden. Wanneer al uw virtuele machines beschikbaar zijn, kunt u verwachten dat er geen resultaten worden ontvangen.
HealthResources
| where type =~ 'microsoft.resourcehealth/availabilitystatuses'
| where tostring(properties.availabilityState) != 'Available'
| summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)
az graph query -q "HealthResources | where type =~ 'microsoft.resourcehealth/availabilitystatuses' | where tostring(properties.availabilityState) != 'Available' | summarize by ResourceId = tolower(tostring(properties.targetResourceId)), AvailabilityState = tostring(properties.availabilityState)"
Lijst van voltooide Windows Server-besturingssysteem updates installatie
Retourneert een lijst met status van Windows Server: installatie van besturingssysteemupdates uitgevoerd voor uw computers in de afgelopen zeven dagen.
PatchAssessmentResources
| where type has 'softwarepatches' and properties !has 'version'
| extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10))
| extend prop = parse_json(properties)
| extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), kbId = tostring(prop.kbId), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications)
| where lTime > ago(7d)
| project lTime, RunID, machineName, rgName, resourceType, patchName, kbId, classifications, installationState
| sort by RunID
az graph query -q "PatchAssessmentResources | where type has 'softwarepatches' and properties !has 'version' | extend machineName = tostring(split(id, '/', 8)), resourceType = tostring(split(type, '/', 0)), tostring(rgName = split(id, '/', 4)), tostring(RunID = split(id, '/', 10)) | extend prop = parse_json(properties) | extend lTime = todatetime(prop.lastModifiedDateTime), patchName = tostring(prop.patchName), kbId = tostring(prop.kbId), installationState = tostring(prop.installationState), classifications = tostring(prop.classifications) | where lTime > ago(7d) | project lTime, RunID, machineName, rgName, resourceType, patchName, kbId, classifications, installationState | sort by RunID"
Een lijst met virtuele machines weergeven met bijbehorende netwerkinterfaces en openbare IP-adressen
Deze query maakt gebruik van twee leftouter
join
opdrachten om virtuele machines samen te voegen die zijn gemaakt met het Resource Manager-implementatiemodel, de bijbehorende netwerkinterfaces en elk openbaar IP-adres dat is gerelateerd aan die netwerkinterfaces.
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| extend nics=array_length(properties.networkProfile.networkInterfaces)
| mv-expand nic=properties.networkProfile.networkInterfaces
| where nics == 1 or nic.properties.primary =~ 'true' or isempty(nic)
| project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id)
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/networkinterfaces'
| extend ipConfigsCount=array_length(properties.ipConfigurations)
| mv-expand ipconfig=properties.ipConfigurations
| where ipConfigsCount == 1 or ipconfig.properties.primary =~ 'true'
| project nicId = id, publicIpId = tostring(ipconfig.properties.publicIPAddress.id))
on nicId
| project-away nicId1
| summarize by vmId, vmName, vmSize, nicId, publicIpId
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/publicipaddresses'
| project publicIpId = id, publicIpAddress = properties.ipAddress)
on publicIpId
| project-away publicIpId1
az graph query -q "Resources | where type =~ 'microsoft.compute/virtualmachines' | extend nics=array_length(properties.networkProfile.networkInterfaces) | mv-expand nic=properties.networkProfile.networkInterfaces | where nics == 1 or nic.properties.primary =~ 'true' or isempty(nic) | project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id) | join kind=leftouter ( Resources | where type =~ 'microsoft.network/networkinterfaces' | extend ipConfigsCount=array_length(properties.ipConfigurations) | mv-expand ipconfig=properties.ipConfigurations | where ipConfigsCount == 1 or ipconfig.properties.primary =~ 'true' | project nicId = id, publicIpId = tostring(ipconfig.properties.publicIPAddress.id)) on nicId | project-away nicId1 | summarize by vmId, vmName, vmSize, nicId, publicIpId | join kind=leftouter ( Resources | where type =~ 'microsoft.network/publicipaddresses' | project publicIpId = id, publicIpAddress = properties.ipAddress) on publicIpId | project-away publicIpId1"
Alle virtuele machines weergeven, aflopend geordend op naam
Als u alleen virtuele machines wilt vermelden (die van het type Microsoft.Compute/virtualMachines
zijn), kan een overeenkomst worden gezocht met de eigenschap type in de resultaten. Net als bij de vorige query verandert desc
de order by
naar aflopend. De =~
in de type-matching geeft in Resource Graph aan dat er geen onderscheid wordt gemaakt tussen hoofdletters en kleine letters.
Resources
| project name, location, type
| where type =~ 'Microsoft.Compute/virtualMachines'
| order by name desc
az graph query -q "Resources | project name, location, type | where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
De eerste vijf virtuele machines weergeven op naam en met hun type besturingssysteem
Deze query gebruikt top
om slechts vijf overeenkomende records op te halen die op naam zijn geordend. Het type van de Azure-resource is Microsoft.Compute/virtualMachines
.
project
geeft in Azure Resource Graph aan welke eigenschappen u wilt opnemen.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| project name, properties.storageProfile.osDisk.osType
| top 5 by name desc
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project name, properties.storageProfile.osDisk.osType | top 5 by name desc"
Virtuele machine samenvatten op basis van de uitgebreide eigenschap voor energiestatussen
Deze query maakt gebruik van de uitgebreide eigenschappen op virtuele machines om deze op energiestatus samen te vatten.
Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by tostring(properties.extended.instanceView.powerState.code)
az graph query -q "Resources | where type == 'microsoft.compute/virtualmachines' | summarize count() by tostring(properties.extended.instanceView.powerState.code)"
Virtuele machines gematcht via reguliere expressies
Deze query zoekt virtuele machines die overeenkomen met een reguliere expressie (ook wel regex genoemd). Met de regex voor overeenkomsten @ kunnen we de regex definiëren die ^Contoso(.*)[0-9]+$
is. De definitie van deze reguliere expressie wordt als volgt uitgelegd:
-
^
: Match moet starten bij het begin van de tekenreeks. -
Contoso
: De hoofdlettergevoelige reeks. -
(.*)
- Een overeenkomst van een subexpressie:-
.
: Komt overeen met een willekeurig teken (met uitzondering van een nieuwe regel). -
*
: Komt nul keer of vaker overeen met vorig element.
-
-
[0-9]
: Tekengroep overeenkomst voor de cijfers 0 t/m 9. -
+
: Komt één keer of vaker overeen met vorig element. -
$
: Overeenkomst met het vorige element moet voorkomen aan het einde van de tekenreeks.
Na de vergelijking op naam projecteert de query de naam en sorteert deze in oplopende volgorde.
Resources
| where type =~ 'microsoft.compute/virtualmachines' and name matches regex @'^Contoso(.*)[0-9]+$'
| project name
| order by name asc
az graph query -q "Resources | where type =~ 'microsoft.compute/virtualmachines' and name matches regex @'^Contoso(.*)[0-9]+\$' | project name | order by name asc"
Volgende stappen
- Meer informatie over de query-taal.
- Lees meer over het verkennen van middelen.