

È stata rilasciata la versione 5 (V5) di\$1 AWS Strumenti per PowerShell 

Per informazioni sulle modifiche introduttive e sulla migrazione delle applicazioni, consulta l'argomento sulla [migrazione](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html).

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Esempi di Resource Groups con Tools for PowerShell V5
<a name="powershell_resource-groups_code_examples"></a>

I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando la AWS Strumenti per PowerShell V5 con Resource Groups.

Le *azioni* sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le azioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.

Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.

**Topics**
+ [Azioni](#actions)

## Azioni
<a name="actions"></a>

### `Add-RGResourceTag`
<a name="resource-groups_Tag_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare`Add-RGResourceTag`.

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio aggiunge la chiave di tag “Instances” con il valore “workboxes” all’ARN del gruppo di risorse specificato**  

```
Add-RGResourceTag -Tag @{Instances="workboxes"} -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes
```
**Output:**  

```
Arn                                                            Tags
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {[Instances, workboxes]}
```
+  Per informazioni dettagliate sull’API, consulta [Tag](https://docs.aws.amazon.com/powershell/v5/reference) nella *documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5)*. 

### `Find-RGResource`
<a name="resource-groups_SearchResources_powershell_topic"></a>

Il seguente esempio di codice mostra come usare`Find-RGResource`.

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio crea un tipo di risorsa ad ResourceQuery esempio con filtri di tag e trova risorse.**  

```
$query = [Amazon.ResourceGroups.Model.ResourceQuery]::new()
$query.Type = [Amazon.ResourceGroups.QueryType]::TAG_FILTERS_1_0
$query.Query = ConvertTo-Json -Compress -Depth 4 -InputObject @{
  ResourceTypeFilters = @('AWS::EC2::Instance')
  TagFilters = @(@{
    Key = 'auto'
    Values = @('no')
  })
 }

Find-RGResource -ResourceQuery $query | Select-Object -ExpandProperty ResourceIdentifiers
```
**Output:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123445b6cb7bd67b AWS::EC2::Instance
```
+  Per i dettagli sull'API, vedere [SearchResources](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (V5)*. 

### `Get-RGGroup`
<a name="resource-groups_GetGroup_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Get-RGGroup`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio recupera il gruppo di risorse in base al nome del gruppo**  

```
Get-RGGroup -GroupName auto-no
```
**Output:**  

```
Description GroupArn                                                     Name
----------- --------                                                     ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no auto-no
```
+  Per i dettagli sull'API, vedere [GetGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `Get-RGGroupList`
<a name="resource-groups_ListGroups_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Get-RGGroupList`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio elenca i gruppi di risorse già creati.**  

```
Get-RGGroupList
```
**Output:**  

```
GroupArn                                                                  GroupName
--------                                                                  ---------
arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no              auto-no
arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes             auto-yes
arn:aws:resource-groups:eu-west-1:123456789012:group/build600             build600
```
+  Per i dettagli sull'API, vedere [ListGroups](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `Get-RGGroupQuery`
<a name="resource-groups_GetGroupQuery_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Get-RGGroupQuery`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio recupera la query di risorse per il gruppo di risorse specificato**  

```
Get-RGGroupQuery -GroupName auto-no | Select-Object -ExpandProperty ResourceQuery
```
**Output:**  

```
Query                                                                                        Type
-----                                                                                        ----
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"auto","Values":["no"]}]} TAG_FILTERS_1_0
```
+  Per i dettagli sull'API, vedere [GetGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `Get-RGGroupResourceList`
<a name="resource-groups_ListGroupResources_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Get-RGGroupResourceList`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio elenca le risorse del gruppo filtrate in base al tipo di risorsa**  

```
Get-RGGroupResourceList -Filter @{Name="resource-type";Values="AWS::EC2::Instance"} -GroupName auto-yes | Select-Object -ExpandProperty ResourceIdentifiers
```
**Output:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123bc45b567890e1 AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-0a1caf2345f67d8dc AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-012e3cb4df567e8aa AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-0fd12dd3456789012 AWS::EC2::Instance
```
+  Per i dettagli sull'API, vedere [ListGroupResources](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `Get-RGResourceTag`
<a name="resource-groups_GetTags_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Get-RGResourceTag`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio elenca i tag per l’ARN del gruppo di risorse specificato**  

```
Get-RGResourceTag -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes
```
**Output:**  

```
Key       Value
---       -----
Instances workboxes
```
+  Per i dettagli sull'API, vedere [GetTags](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `New-RGGroup`
<a name="resource-groups_CreateGroup_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `New-RGGroup`

**Strumenti per PowerShell V5**  
**Esempio 1: Questo esempio crea un nuovo gruppo di AWS risorse Resource Groups basato su tag denominato TestPowerShellGroup. Il gruppo include EC2 istanze Amazon nella regione corrente contrassegnate con la chiave di tag «Name» e il valore del tag «test2". Il comando restituisce la query e il tipo di gruppo e i risultati dell’operazione.**  

```
$ResourceQuery = New-Object -TypeName Amazon.ResourceGroups.Model.ResourceQuery
$ResourceQuery.Type = "TAG_FILTERS_1_0"
$ResourceQuery.Query = '{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"Name","Values":["test2"]}]}'
$ResourceQuery

New-RGGroup -Name TestPowerShellGroup -ResourceQuery $ResourceQuery -Description "Test resource group."
```
**Output:**  

```
Query                                                                                           Type           
-----                                                                                           ----           
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"Name","Values":["test2"]}]} TAG_FILTERS_1_0

LoggedAt         : 11/20/2018 2:40:59 PM
Group            : Amazon.ResourceGroups.Model.Group
ResourceQuery    : Amazon.ResourceGroups.Model.ResourceQuery
Tags             : {}
ResponseMetadata : Amazon.Runtime.ResponseMetadata
ContentLength    : 338
HttpStatusCode   : OK
```
+  Per i dettagli sull'API, consulta *AWS Strumenti per PowerShell Cmdlet [CreateGroup](https://docs.aws.amazon.com/powershell/v5/reference)Reference (*V5). 

### `Remove-RGGroup`
<a name="resource-groups_DeleteGroup_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Remove-RGGroup`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio rimuove il gruppo di risorse denominato**  

```
Remove-RGGroup -GroupName non-tag-cfn-elbv2
```
**Output:**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-RGGroup (DeleteGroup)" on target "non-tag-cfn-elbv2".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Description GroupArn                                                               Name
----------- --------                                                               ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/non-tag-cfn-elbv2 non-tag-cfn-elbv2
```
+  Per i dettagli sull'API, vedere [DeleteGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `Remove-RGResourceTag`
<a name="resource-groups_Untag_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Remove-RGResourceTag`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio rimuove il tag menzionato dal gruppo di risorse**  

```
Remove-RGResourceTag -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes -Key Instances
```
**Output:**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-RGResourceTag (Untag)" on target "arn:aws:resource-groups:eu-west-1:933303704102:group/workboxes".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Arn                                                            Keys
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {Instances}
```
+  Per informazioni dettagliate sull’API, consulta [Untag](https://docs.aws.amazon.com/powershell/v5/reference) nella *documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5)*. 

### `Update-RGGroup`
<a name="resource-groups_UpdateGroup_powershell_topic"></a>

Il seguente esempio di codice mostra come usare`Update-RGGroup`.

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio aggiorna la descrizione del gruppo**  

```
Update-RGGroup -GroupName auto-yes -Description "Instances auto-remove"
```
**Output:**  

```
Description             GroupArn                                                      Name
-----------             --------                                                      ----
Instances to be cleaned arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes auto-yes
```
+  Per i dettagli sull'API, vedere [UpdateGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

### `Update-RGGroupQuery`
<a name="resource-groups_UpdateGroupQuery_powershell_topic"></a>

Il seguente esempio di codice mostra come utilizzare. `Update-RGGroupQuery`

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio crea un oggetto query e aggiorna la query per il gruppo.**  

```
$query = [Amazon.ResourceGroups.Model.ResourceQuery]::new()
$query.Type = [Amazon.ResourceGroups.QueryType]::TAG_FILTERS_1_0
$query.Query = @{
  ResourceTypeFilters = @('AWS::EC2::Instance')
  TagFilters = @(@{
  Key='Environment'
  Values='Build600.11'
  })
} | ConvertTo-Json -Compress -Depth 4

Update-RGGroupQuery -GroupName build600 -ResourceQuery $query
```
**Output:**  

```
GroupName ResourceQuery
--------- -------------
build600  Amazon.ResourceGroups.Model.ResourceQuery
```
+  Per i dettagli sull'API, vedere [UpdateGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 