Get-AzureResource

Get-AzureResource

Gets Azure resources

Syntax

Parameter Set: List resources
Get-AzureResource [-ResourceGroupName <String> ] [-ResourceType <String> ] [ <CommonParameters>]

Parameter Set: Get a single resource
Get-AzureResource [-Name] <String> -ApiVersion <String> -ResourceGroupName <String> -ResourceType <String> [-ParentResource <String> ] [ <CommonParameters>]

Detailed Description

The Get-AzureResource cmdlet gets the Azure resources in the subscription. By default, it gets all resources in the subscription, but you can use the parameters in the cmdlet to filter the results.

An Azure resource is a user-managed Azure entity, such as a database server, database, or website. Every Azure resource is associated with a resource group, which is a collection of resources that are deployed as a unit.

Parameters

-ApiVersion<String>

Specifies the API version that is supported by the resource provider. This parameter is required.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Name<String>

Gets a resource with the specified name. Wildcards are not permitted. This parameter is required only when you are selecting resource by name. By default, Get-AzureResource gets all resources in the subscription.

Aliases

ResourceName

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ParentResource<String>

Gets only resources that are children of the specified parent resource. Enter the fully qualified name of the parent resource, such as " Microsoft.Sql/servers/ContosoSQLSvr". Wildcards are not permitted.

Use this parameter when the resource is a type that has parents. For example, every SQL Azure database is associated with a SQL Azure database server. A resource group is not a parent of its resources.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ResourceGroupName<String>

Gets only resources in the specified resource group. Wildcards are not permitted. This parameter is required only when you are selecting resources by name. By default, Get-AzureResource gets all resources in the subscription.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ResourceType<String>

Gets only resources of the specified resource type. Wildcards are not permitted. This parameter is required only when you are selecting resources by name. By default, GetAzureResource gets all resources in the subscription.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You can pipe input to this cmdlet by property name, but not by value.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Azure.Commands.ResourceManagement.Models.PSResource

    Returns objects that represent the resouces.

Notes

  • The Get-AzureResource cmdlet is included in the Azure Resource Manager module beginning in module version 0.8.0.

Examples

Example 1: Get all resources

This commands gets all Azure resources in the subscription.

PS C:\> Get-AzureResource
Name              : HostingFarm1
ResourceGroupName : ContosoHosting
ResourceType : Microsoft.Web/serverFarms
Location : southcentralus
Properties :


Name : ContosoDev
ResourceGroupName : ContosoLabsRG
ResourceType : Microsoft.Web/sites
Location : southcentralus
Properties :
...

Example 2: Get resources by resource group

This commands gets all Azure resources in the ContosoRG01 resource group.

PS C:\> Get-AzureResource -ResourceGroupName ContosoRG01
                       
Name              : Default1
ResourceGroupName : ContosoLabsRG
ResourceType : Microsoft.Web/serverFarms
Location : northeurope
Properties :


Name : ContosoLabWeb
ResourceGroupName : ContosoLabsRG
ResourceType : Microsoft.Web/sites
Location : northeurope
Properties :

Example 2: Get resources by resource type

These commands get all resources with a specified resource type.

The first command finds the types of resources in the subscription. It uses the Get-AzureResource cmdlet to get all resources and Group-Object cmdlet to group the objects by resource type. The output shows that there are server farms and web sites in the subscription.

The second command uses the ResourceType parameter of Get-AzureResource to get all server farms in the subscription.

PS C:\>Get-AzureResource | Group-Object ResourceType

Count Name                      Group
----- ----                      -----    
4 Microsoft.Web/serverFarms {Microsoft.Azure.Commands.ResourceManagement.Models.PSResource, Microsoft.Azure.Comm...     
4 Microsoft.Web/sites       {Microsoft.Azure.Commands.ResourceManagement.Models.PSResource, Microsoft.Azure.Comm... 


PS C:\>Get-AzureResource -ResourceType Microsoft.Web/serverFarms
Name              : Default1
ResourceGroupName :
ResourceType : Microsoft.Web/serverFarms
Location : southcentralus
Properties :


Name : Default1
ResourceGroupName :
ResourceType : Microsoft.Web/serverFarms
Location : northeurope
Properties :


Name : Default1
ResourceGroupName :
ResourceType : Microsoft.Web/serverFarms
Location : southcentralus
Properties :


Name : Default2
ResourceGroupName :
ResourceType : Microsoft.Web/serverFarms
Location : southcentralus
Properties :

Example 3: Get a resource by name

This commands gets the "ContosoLabWeb" web site resource. When you use the Name parameter to get a particular resource, the ResourceGroupName, ResourceType, and APIVersion parameters are required.

You can also use the Where-Object cmdlet to select a resource. For example: Get-AzureResource | Where-Object Name -eq "ConsotoLabWeb"

PS C:\> Get-AzureResource -Name ContosoLabWeb -ResourceGroupName ContosoLabsRG -ResourceType "Microsoft.Web/sites" -ApiVersion 2014-04-01
Name              : ContosoLabWeb
ResourceGroupName : ContosoLabsRG
ResourceType : Microsoft.Web/sites
Location : North Europe
Properties :
{[name, ContosoLabWeb], [state, Running], [hostNames,
System.Collections.Generic.List`1[System.Object]], [webSpace,
ContosoLabsRG-NorthEuropewebspace]...}