

• AWS Systems Manager CloudWatch ダッシュボードは、2026 年 4 月 30 日以降は利用できなくなります。お客様は、これまでと同様に Amazon CloudWatch コンソールを使用して、Amazon CloudWatch ダッシュボードの表示、作成、管理を継続できます。詳細については、「[Amazon CloudWatch ダッシュボードのドキュメント](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)」を参照してください。

# CLI で `RegisterTargetWithMaintenanceWindow` を使用する
<a name="example_ssm_RegisterTargetWithMaintenanceWindow_section"></a>

次のサンプルコードは、`RegisterTargetWithMaintenanceWindow` を使用する方法を説明しています。

------
#### [ CLI ]

**AWS CLI**  
**例 1: メンテナンスウィンドウに単一のターゲットを登録するには**  
次の `register-target-with-maintenance-window` の例では、インスタンスをメンテナンスウィンドウに登録します。  

```
aws ssm register-target-with-maintenance-window \
    --window-id {{"mw-ab12cd34ef56gh78"}} \
    --target {{"Key=InstanceIds,Values=i-0000293ffd8c57862"}} \
    --owner-information {{"Single instance"}} \
    --resource-type {{"INSTANCE"}}
```
出力:  

```
{
    "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d-1a2"
}
```
**例 2: インスタンス ID を使用して、メンテナンスウィンドウに複数のターゲットを登録するには**  
次の `register-target-with-maintenance-window` の例では、インスタンス ID を指定して、2 つのインスタンスをメンテナンスウィンドウに登録します。  

```
aws ssm register-target-with-maintenance-window \
    --window-id {{"mw-ab12cd34ef56gh78"}} \
    --target {{"Key=InstanceIds,Values=i-0000293ffd8c57862,i-0cb2b964d3e14fd9f"}} \
    --owner-information {{"Two instances in a list"}} \
    --resource-type {{"INSTANCE"}}
```
出力:  

```
{
    "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d-1a2"
}
```
**例 3: リソースタグを使用してメンテナンスウィンドウにターゲットを登録するには**  
次の `register-target-with-maintenance-window` の例では、インスタンスに適用されたリソースタグを指定して、インスタンスをメンテナンスウィンドウに登録します。  

```
aws ssm register-target-with-maintenance-window \
    --window-id {{"mw-06cf17cbefcb4bf4f"}} \
    --targets {{"Key=tag:Environment,Values=Prod"}} {{"Key=Role,Values=Web"}} \
    --owner-information {{"Production Web Servers"}} \
    --resource-type {{"INSTANCE"}}
```
出力:  

```
{
    "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d-1a2"
}
```
**例 4: タグキーのグループを使用してターゲットを登録するには**  
次の `register-target-with-maintenance-window` の例では、キー値に関係なく、1 つまたは複数のタグキーが割り当てられているインスタンスをすべて登録します。  

```
aws ssm register-target-with-maintenance-window \
    --window-id {{"mw-0c50858d01EXAMPLE"}} \
    --resource-type {{"INSTANCE"}} \
    --target {{"Key=tag-key,Values=Name,Instance-Type,CostCenter"}}
```
出力:  

```
{
    "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d-1a2"
}
```
**例 5: リソースグループ名を使用してターゲットを登録するには**  
次の `register-target-with-maintenance-window` の例では、含まれるリソースタイプに関係なく、指定されたリソースグループを登録します。  

```
aws ssm register-target-with-maintenance-window \
    --window-id {{"mw-0c50858d01EXAMPLE"}} \
    --resource-type {{"RESOURCE_GROUP"}} \
    --target {{"Key=resource-groups:Name,Values=MyResourceGroup"}}
```
出力:  

```
{
    "WindowTargetId":"1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d-1a2"
}
```
詳細については、「*AWS Systems Manager ユーザーガイド*」の「[メンテナンスウィンドウを使用してターゲットインスタンスを登録する (AWS CLI)](https://docs.aws.amazon.com/systems-manager/latest/userguide/mw-cli-tutorial-targets.html)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[RegisterTargetWithMaintenanceWindow](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ssm/register-target-with-maintenance-window.html)」を参照してください。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**例 1: この例では、インスタンスをメンテナンスウィンドウに登録します。**  

```
$option1 = @{Key="InstanceIds";Values=@("i-0000293ffd8c57862")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Single instance" -ResourceType "INSTANCE"
```
**出力:**  

```
d8e47760-23ed-46a5-9f28-927337725398
```
**例 2: この例では、複数のインスタンスをメンテナンスウィンドウに登録します。**  

```
$option1 = @{Key="InstanceIds";Values=@("i-0000293ffd8c57862","i-0cb2b964d3e14fd9f")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Single instance" -ResourceType "INSTANCE"
```
**出力:**  

```
6ab5c208-9fc4-4697-84b7-b02a6cc25f7d
```
**例 3: この例では、EC2 タグを使用して、インスタンスをメンテナンスウィンドウに登録します。**  

```
$option1 = @{Key="tag:Environment";Values=@("Production")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Production Web Servers" -ResourceType "INSTANCE"
```
**出力:**  

```
2994977e-aefb-4a71-beac-df620352f184
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V4)* の「[RegisterTargetWithMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

**Tools for PowerShell V5**  
**例 1: この例では、インスタンスをメンテナンスウィンドウに登録します。**  

```
$option1 = @{Key="InstanceIds";Values=@("i-0000293ffd8c57862")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Single instance" -ResourceType "INSTANCE"
```
**出力:**  

```
d8e47760-23ed-46a5-9f28-927337725398
```
**例 2: この例では、複数のインスタンスをメンテナンスウィンドウに登録します。**  

```
$option1 = @{Key="InstanceIds";Values=@("i-0000293ffd8c57862","i-0cb2b964d3e14fd9f")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Single instance" -ResourceType "INSTANCE"
```
**出力:**  

```
6ab5c208-9fc4-4697-84b7-b02a6cc25f7d
```
**例 3: この例では、EC2 タグを使用して、インスタンスをメンテナンスウィンドウに登録します。**  

```
$option1 = @{Key="tag:Environment";Values=@("Production")}
Register-SSMTargetWithMaintenanceWindow -WindowId "mw-06cf17cbefcb4bf4f" -Target $option1 -OwnerInformation "Production Web Servers" -ResourceType "INSTANCE"
```
**出力:**  

```
2994977e-aefb-4a71-beac-df620352f184
```
+  API の詳細については、AWS Tools for PowerShell Cmdlet リファレンス (V5) の「[RegisterTargetWithMaintenanceWindow](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

------

AWS SDK デベロッパーガイドとコード例の詳細なリストについては、[このサービスを AWS SDK で使用する](sdk-general-information-section.md) を参照してください。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。