

Versi 5 (V5) dari Alat AWS untuk PowerShell telah dirilis\$1

Untuk informasi tentang melanggar perubahan dan memigrasi aplikasi Anda, lihat [topik migrasi](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)

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Contoh Resource Groups menggunakan Alat untuk PowerShell V5
<a name="powershell_resource-groups_code_examples"></a>

Contoh kode berikut menunjukkan cara melakukan tindakan dan mengimplementasikan skenario umum dengan menggunakan Alat AWS untuk PowerShell V5 dengan Resource Groups.

*Tindakan* merupakan kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

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

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

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

Contoh kode berikut menunjukkan cara menggunakan`Add-RGResourceTag`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini menambahkan kunci tag 'Instances' dengan nilai 'kotak kerja' ke grup sumber daya yang diberikan arn**  

```
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]}
```
+  Untuk detail API, lihat [Tag](https://docs.aws.amazon.com/powershell/v5/reference) di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Find-RGResource`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini membuat tipe sumber daya ResourceQuery untuk Instance dengan filter tag dan menemukan sumber daya.**  

```
$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
```
+  Untuk detail API, lihat [SearchResources](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Get-RGGroup`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini mengambil grup sumber daya sesuai nama grup**  

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

```
Description GroupArn                                                     Name
----------- --------                                                     ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no auto-no
```
+  Untuk detail API, lihat [GetGroup](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Get-RGGroupList`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini mencantumkan grup sumber daya yang sudah dibuat.**  

```
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
```
+  Untuk detail API, lihat [ListGroups](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Get-RGGroupQuery`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini mengambil kueri sumber daya untuk grup sumber daya yang diberikan**  

```
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
```
+  Untuk detail API, lihat [GetGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Get-RGGroupResourceList`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini mencantumkan sumber daya grup berdasarkan disaring berdasarkan jenis sumber daya**  

```
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
```
+  Untuk detail API, lihat [ListGroupResources](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Get-RGResourceTag`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini mencantumkan tag untuk kelompok sumber daya yang diberikan arn**  

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

```
Key       Value
---       -----
Instances workboxes
```
+  Untuk detail API, lihat [GetTags](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`New-RGGroup`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini membuat grup AWS sumber daya Resource Groups berbasis tag baru bernama TestPowerShellGroup. Grup ini menyertakan EC2 instance Amazon di wilayah saat ini yang ditandai dengan kunci tag “Nama”, dan nilai tag “test2". Perintah mengembalikan query dan jenis grup, dan hasil operasi.**  

```
$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
```
+  Untuk detail API, lihat [CreateGroup](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Remove-RGGroup`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini menghapus grup sumber daya bernama**  

```
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
```
+  Untuk detail API, lihat [DeleteGroup](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Remove-RGResourceTag`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini menghapus tag yang disebutkan dari grup sumber daya**  

```
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}
```
+  Untuk detail API, lihat [Membatalkan tag](https://docs.aws.amazon.com/powershell/v5/reference) di *Referensi Alat AWS untuk PowerShell Cmdlet (*V5). 

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

Contoh kode berikut menunjukkan cara menggunakan`Update-RGGroup`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini memperbarui deskripsi grup**  

```
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
```
+  Untuk detail API, lihat [UpdateGroup](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 

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

Contoh kode berikut menunjukkan cara menggunakan`Update-RGGroupQuery`.

**Alat untuk PowerShell V5**  
**Contoh 1: Contoh ini membuat objek query dan memperbarui query untuk grup.**  

```
$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
```
+  Untuk detail API, lihat [UpdateGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)di *Referensi Alat AWS untuk PowerShell Cmdlet (V5)*. 