Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Get-AzResource

Gets resources.

Syntax

ByTagNameValueParameterSet (Default)

Get-AzResource
 [-Name <String>]
 [-ResourceType <String>]
 [-ODataQuery <String>]
 [-ResourceGroupName <String>]
 [-TagName <String>]
 [-TagValue <String>]
 [-ExpandProperties]
 [-ApiVersion <String>]
 [-Pre]
 [-DefaultProfile <IAzureContextContainer>]
 [<CommonParameters>]

ByResourceId

Get-AzResource
 -ResourceId <String>
 [-ODataQuery <String>]
 [-ExpandProperties]
 [-ApiVersion <String>]
 [-Pre]
 [-DefaultProfile <IAzureContextContainer>]
 [<CommonParameters>]

ByTagObjectParameterSet

Get-AzResource
 -Tag <Hashtable>
 [-Name <String>]
 [-ResourceType <String>]
 [-ODataQuery <String>]
 [-ResourceGroupName <String>]
 [-ExpandProperties]
 [-ApiVersion <String>]
 [-Pre]
 [-DefaultProfile <IAzureContextContainer>]
 [<CommonParameters>]

Description

The Get-AzResource cmdlet gets Azure resources.

Examples

Example 1: Get all resources in the current subscription

Get-AzResource | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
disk testRG Microsoft.Compute/disks westus
nic testRG Microsoft.Network/networkInterfaces westus
nsg testRG Microsoft.Network/networkSecurityGroups westus
ip testRG Microsoft.Network/publicIPAddresses westus
vnet testRG Microsoft.Network/virtualNetworks westus
testKV otherRG Microsoft.KeyVault/vaults eastus
storage otherResourceGroup Microsoft.Storage/storageAccounts eastus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus

This command gets all of the resources in the current subscription.

Example 2: Get all resources in a resource group

Get-AzResource -ResourceGroupName testRG | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
disk testRG Microsoft.Compute/disks westus
nic testRG Microsoft.Network/networkInterfaces westus
nsg testRG Microsoft.Network/networkSecurityGroups westus
ip testRG Microsoft.Network/publicIPAddresses westus
vnet testRG Microsoft.Network/virtualNetworks westus

This command gets all of the resources in the resource group "testRG".

Example 3: Get all resources whose resource group matches the provided wildcard

Get-AzResource -ResourceGroupName other* | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testKV otherRG Microsoft.KeyVault/vaults eastus
storage otherResourceGroup Microsoft.Storage/storageAccounts eastus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus

This command gets all of the resources whose resource group they belong in beings with "other".

Example 4: Get all resources with a given name

Get-AzResource -Name testVM | Format-List
Name : testVM
ResourceGroupName : testRG
ResourceType : Microsoft.Compute/virtualMachines
Location : westus
ResourceId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Compute/virtualMachines/testVM
Tags :
 Name Value
 ====== ========
 Dept IT
 Year 2002
 Status Approved

This command gets all of the resources whose resource name is "testVM".

Example 5: Get all resources whose name matches the provided wildcard

Get-AzResource -Name test* | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
testKV otherRG Microsoft.KeyVault/vaults eastus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus

This command gets all of the resources whose resource name begins with "test".

Example 6: Get all resources of a given resource type

Get-AzResource -ResourceType Microsoft.Compute/virtualMachines | Format-Table
Name ResourceGroupName ResourceType Location
---- ----------------- ------------ --------
testVM testRG Microsoft.Compute/virtualMachines westus
testVM2 otherResourceGroup Microsoft.Compute/virtualMachines eastus

This command gets all of the resources in the current subscriptions that are virtual machines.

Example 7: Get a resource by resource id

Get-AzResource -ResourceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Compute/virtualMachines/testVM
Name : testVM
ResourceGroupName : testRG
ResourceType : Microsoft.Compute/virtualMachines
Location : westus
ResourceId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testRG/providers/Microsoft.Compute/virtualMachines/testVM
Tags :
 Name Value
 ====== ========
 Dept IT
 Year 2002
 Status Approved

This command gets the resource with the provided resource id, which is a virtual machine called "testVM" in the resource group "testRG".

Example 8: Get a resource with expanded properties

Get-AzResource -Name testVM -ResourceGroupName testRG -ExpandProperties

This command gets the resource named "testVM" in the resource group "testRG" and expands the properties to include additional details such as CreatedTime, ChangedTime, and other resource metadata.

Parameters

-ApiVersion

The Get-AzResource cmdlet gets Azure resources.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

-ExpandProperties

When specified, expands the properties of the resource.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Name

The name of the resource(s) to be retrieved. This parameter supports wildcards at the beginning and/or end of the string.

Parameter properties

Type:String
Default value:None
Supports wildcards:True
DontShow:False
Aliases:ResourceName

Parameter sets

-ODataQuery

The Get-AzResource cmdlet gets Azure resources.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Pre

The Get-AzResource cmdlet gets Azure resources.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-ResourceGroupName

The resource group the resource(s) that is retrieved belongs in. This parameter supports wildcards at the beginning and/or end of the string.

Parameter properties

Type:String
Default value:None
Supports wildcards:True
DontShow:False

Parameter sets

-ResourceId

Specifies the fully qualified resource ID, as in the following example /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Compute/virtualMachines

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:Id

Parameter sets

-ResourceType

The resource type of the resource(s) to be retrieved. For example, Microsoft.Compute/virtualMachines

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Tag

Gets resources that have the specified Azure tag. Enter a hash table with a Name key or Name and Value keys. Wildcard characters are not supported.A "tag" is a name-value pair that you can apply to resources and resource groups. Use tags to categorize your resources, such as by department or cost center, or to track notes or comments about the resources. To add a tag to a resource, use the Tag parameter of the New-AzResource or Set-AzResource cmdlets. To create a predefined tag, use the New-AzTag cmdlet. For help with hash tables in Windows PowerShell, run 'Get-Help about_Hashtables'.

Parameter properties

Type:Hashtable
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-TagName

The key in the tag of the resource(s) to be retrieved.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-TagValue

The value in the tag of the resource(s) to be retrieved.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

Outputs

PSResource

Related Links


Feedback

Was this page helpful?