

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 将 `RegisterTargetWithMaintenanceWindow` 与 CLI 配合使用
<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 向维护时段注册两个实例。  

```
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` 示例注册所有被分配了一个或多个标签键的实例（不考虑其键值）。  

```
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 Command Reference》**中的 [RegisterTargetWithMaintenanceWindow](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ssm/register-target-with-maintenance-window.html)。

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

**适用于 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 Cmdlet Reference（V4）》中的 [RegisterTargetWithMaintenanceWindow](https://docs.aws.amazon.com/powershell/v4/reference)**。

**适用于 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 版本的详细信息。