

のバージョン 5 (V5) AWS Tools for PowerShell がリリースされました。

重要な変更とアプリケーションの移行については、[「移行トピック](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)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Tools for PowerShell V5 を使用した Resource Groups の例
<a name="powershell_resource-groups_code_examples"></a>

次のコード例は、リソースグループで AWS Tools for PowerShell V5 を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

**Topics**
+ [アクション](#actions)

## アクション
<a name="actions"></a>

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

次のコード例は、`Add-RGResourceTag` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、指定されたリソースグループ ARN に値「workboxes」を持つタグキー「Instances」を追加します。**  

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

```
Arn                                                            Tags
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {[Instances, workboxes]}
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[Tag](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Find-RGResource` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、タグフィルターを使用してインスタンスリソースタイプの ResourceQuery を作成し、リソースを検索します。**  

```
$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
```
**出力:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123445b6cb7bd67b AWS::EC2::Instance
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[SearchResources](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Get-RGGroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、グループ名に従ってリソースグループを取得します。**  

```
Get-RGGroup -GroupName auto-no
```
**出力:**  

```
Description GroupArn                                                     Name
----------- --------                                                     ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no auto-no
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[GetGroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Get-RGGroupList` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、既に作成されたリソースグループを一覧表示します。**  

```
Get-RGGroupList
```
**出力:**  

```
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
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[ListGroups](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Get-RGGroupQuery` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、指定されたリソースグループのリソースクエリを取得します。**  

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

```
Query                                                                                        Type
-----                                                                                        ----
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"auto","Values":["no"]}]} TAG_FILTERS_1_0
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[GetGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Get-RGGroupResourceList` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、リソースタイプでフィルタリングされたグループリソースを一覧表示します。**  

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

```
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
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[ListGroupResources](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Get-RGResourceTag` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、指定されたリソースグループ ARN のタグを一覧表示します。**  

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

```
Key       Value
---       -----
Instances workboxes
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[GetTags](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`New-RGGroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、TestPowerShellGroup という名前の新しいタグベースの AWS Resource Groups リソースグループを作成します。グループには、タグキー「Name」とタグ値「test2」でタグ付けされた現在のリージョンの Amazon EC2 インスタンスが含まれます。コマンドは、クエリとグループのタイプ、および操作の結果を返します。**  

```
$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."
```
**出力:**  

```
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
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[CreateGroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Remove-RGGroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、名前付きリソースグループを削除します。**  

```
Remove-RGGroup -GroupName non-tag-cfn-elbv2
```
**出力:**  

```
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
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[DeleteGroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Remove-RGResourceTag` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、リソースグループから指定されたタグを削除します。**  

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

```
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}
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[Untag](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Update-RGGroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、グループの説明を更新します。**  

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

```
Description             GroupArn                                                      Name
-----------             --------                                                      ----
Instances to be cleaned arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes auto-yes
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[UpdateGroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Update-RGGroupQuery` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: この例では、クエリオブジェクトを作成し、グループのクエリを更新します。**  

```
$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
```
**出力:**  

```
GroupName ResourceQuery
--------- -------------
build600  Amazon.ResourceGroups.Model.ResourceQuery
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[UpdateGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**